Documentation ¶
Index ¶
- Constants
- func ArchiveOrg(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, ...) ([]*Archive, []*Archive, error)
- func BuildRollupArchive(ctx context.Context, db *sqlx.DB, conf *Config, s3Client s3iface.S3API, ...) error
- func CreateArchiveFile(ctx context.Context, db *sqlx.DB, archive *Archive, archivePath string) error
- func DeleteArchiveFile(archive *Archive) error
- func DeleteArchivedMessages(ctx context.Context, config *Config, db *sqlx.DB, s3Client s3iface.S3API, ...) error
- func DeleteArchivedRuns(ctx context.Context, config *Config, db *sqlx.DB, s3Client s3iface.S3API, ...) error
- func EnsureTempArchiveDirectory(path string) error
- func GetCurrentArchiveCount(ctx context.Context, db *sqlx.DB, org Org, archiveType ArchiveType) (int, error)
- func GetS3File(ctx context.Context, s3Client s3iface.S3API, fileURL string) (io.ReadCloser, error)
- func GetS3FileETAG(ctx context.Context, s3Client s3iface.S3API, fileURL string) (string, error)
- func NewS3Client(config *Config) (s3iface.S3API, error)
- func TestS3(s3Client s3iface.S3API, bucket string) error
- func UploadArchive(ctx context.Context, s3Client s3iface.S3API, bucket string, archive *Archive) error
- func UploadToS3(ctx context.Context, s3Client s3iface.S3API, bucket string, path string, ...) error
- func WriteArchiveToDB(ctx context.Context, db *sqlx.DB, archive *Archive) error
- type Archive
- func CreateOrgArchives(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, ...) ([]*Archive, error)
- func DeleteArchivedOrgRecords(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, ...) ([]*Archive, error)
- func GetArchivesNeedingDeletion(ctx context.Context, db *sqlx.DB, org Org, archiveType ArchiveType) ([]*Archive, error)
- func GetCurrentArchives(ctx context.Context, db *sqlx.DB, org Org, archiveType ArchiveType) ([]*Archive, error)
- func GetDailyArchivesForDateRange(ctx context.Context, db *sqlx.DB, org Org, archiveType ArchiveType, ...) ([]*Archive, error)
- func GetMissingDailyArchives(ctx context.Context, db *sqlx.DB, now time.Time, org Org, ...) ([]*Archive, error)
- func GetMissingDailyArchivesForDateRange(ctx context.Context, db *sqlx.DB, startDate time.Time, endDate time.Time, ...) ([]*Archive, error)
- func GetMissingMonthlyArchives(ctx context.Context, db *sqlx.DB, now time.Time, org Org, ...) ([]*Archive, error)
- func RollupOrgArchives(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, ...) ([]*Archive, error)
- type ArchivePeriod
- type ArchiveType
- type Config
- type Org
Constants ¶
const ( // RunType for run archives RunType = ArchiveType("run") // MessageType for message archives MessageType = ArchiveType("message") // SessionType for session archives SessionType = ArchiveType("session") )
const ( // DayPeriod id the period of a day (24 hours) from archive start date DayPeriod = ArchivePeriod("D") // MonthPeriod is the period of a month from archive start date MonthPeriod = ArchivePeriod("M") )
Variables ¶
This section is empty.
Functions ¶
func ArchiveOrg ¶ added in v0.0.6
func ArchiveOrg(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, s3Client s3iface.S3API, org Org, archiveType ArchiveType) ([]*Archive, []*Archive, error)
ArchiveOrg looks for any missing archives for the passed in org, creating and uploading them as necessary, returning the created archives
func BuildRollupArchive ¶ added in v0.0.9
func BuildRollupArchive(ctx context.Context, db *sqlx.DB, conf *Config, s3Client s3iface.S3API, monthlyArchive *Archive, now time.Time, org Org, archiveType ArchiveType) error
BuildRollupArchive builds a monthly archive from the files present on S3
func CreateArchiveFile ¶ added in v0.0.6
func CreateArchiveFile(ctx context.Context, db *sqlx.DB, archive *Archive, archivePath string) error
CreateArchiveFile is responsible for writing an archive file for the passed in archive from our database
func DeleteArchiveFile ¶ added in v0.0.6
DeleteArchiveFile removes our own disk archive file
func DeleteArchivedMessages ¶ added in v0.0.11
func DeleteArchivedMessages(ctx context.Context, config *Config, db *sqlx.DB, s3Client s3iface.S3API, archive *Archive) error
DeleteArchivedMessages takes the passed in archive, verifies the S3 file is still present (and correct), then selects all the messages in the archive date range, and if equal or fewer than the number archived, deletes them 100 at a time
Upon completion it updates the needs_deletion flag on the archive
func DeleteArchivedRuns ¶ added in v0.0.18
func DeleteArchivedRuns(ctx context.Context, config *Config, db *sqlx.DB, s3Client s3iface.S3API, archive *Archive) error
DeleteArchivedRuns takes the passed in archive, verifies the S3 file is still present (and correct), then selects all the runs in the archive date range, and if equal or fewer than the number archived, deletes them 100 at a time
Upon completion it updates the needs_deletion flag on the archive
func EnsureTempArchiveDirectory ¶ added in v0.0.6
EnsureTempArchiveDirectory checks that we can write to our archive directory, creating it first if needbe
func GetCurrentArchiveCount ¶ added in v0.0.11
func GetCurrentArchiveCount(ctx context.Context, db *sqlx.DB, org Org, archiveType ArchiveType) (int, error)
GetCurrentArchiveCount returns all the current archives for the passed in org and record type
func GetS3File ¶ added in v0.0.6
GetS3File return an io.ReadCloser for the passed in bucket and path
func GetS3FileETAG ¶ added in v0.0.11
GetS3FileETAG returns the ETAG hash for the passed in file
func NewS3Client ¶ added in v0.0.6
NewS3Client creates a new s3 client from the passed in config, testing it as necessary
func TestS3 ¶ added in v0.0.6
TestS3 tests whether the passed in s3 client is properly configured and the passed in bucket is accessible
func UploadArchive ¶
func UploadArchive(ctx context.Context, s3Client s3iface.S3API, bucket string, archive *Archive) error
UploadArchive uploads the passed archive file to S3
Types ¶
type Archive ¶ added in v0.0.6
type Archive struct { ID int `db:"id"` ArchiveType ArchiveType `db:"archive_type"` OrgID int `db:"org_id"` CreatedOn time.Time `db:"created_on"` StartDate time.Time `db:"start_date"` Period ArchivePeriod `db:"period"` RecordCount int `db:"record_count"` Size int64 `db:"size"` Hash string `db:"hash"` URL string `db:"url"` BuildTime int `db:"build_time"` NeedsDeletion bool `db:"needs_deletion"` DeletedOn *time.Time `db:"deleted_date"` Rollup *int `db:"rollup_id"` Org Org ArchiveFile string Dailies []*Archive }
Archive represents the model for an archive
func CreateOrgArchives ¶ added in v0.0.9
func CreateOrgArchives(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, s3Client s3iface.S3API, org Org, archiveType ArchiveType) ([]*Archive, error)
CreateOrgArchives builds all the missing archives for the passed in org
func DeleteArchivedOrgRecords ¶ added in v0.0.11
func DeleteArchivedOrgRecords(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, s3Client s3iface.S3API, org Org, archiveType ArchiveType) ([]*Archive, error)
DeleteArchivedOrgRecords deletes all the records for the passeg in org based on archives already created
func GetArchivesNeedingDeletion ¶ added in v0.0.11
func GetArchivesNeedingDeletion(ctx context.Context, db *sqlx.DB, org Org, archiveType ArchiveType) ([]*Archive, error)
GetArchivesNeedingDeletion returns all the archives which need to be deleted
func GetCurrentArchives ¶ added in v0.0.6
func GetCurrentArchives(ctx context.Context, db *sqlx.DB, org Org, archiveType ArchiveType) ([]*Archive, error)
GetCurrentArchives returns all the current archives for the passed in org and record type
func GetDailyArchivesForDateRange ¶ added in v0.0.11
func GetDailyArchivesForDateRange(ctx context.Context, db *sqlx.DB, org Org, archiveType ArchiveType, startDate time.Time, endDate time.Time) ([]*Archive, error)
GetDailyArchivesForDateRange returns all the current archives for the passed in org and record type and date range
func GetMissingDailyArchives ¶ added in v0.0.11
func GetMissingDailyArchives(ctx context.Context, db *sqlx.DB, now time.Time, org Org, archiveType ArchiveType) ([]*Archive, error)
GetMissingDailyArchives calculates what archives need to be generated for the passed in org this is calculated per day
func GetMissingDailyArchivesForDateRange ¶ added in v0.0.11
func GetMissingDailyArchivesForDateRange(ctx context.Context, db *sqlx.DB, startDate time.Time, endDate time.Time, org Org, archiveType ArchiveType) ([]*Archive, error)
GetMissingDailyArchivesForDateRange returns all them missing daily archives between the two passed in date ranges
type ArchivePeriod ¶ added in v0.0.6
type ArchivePeriod string
ArchivePeriod is the period of data in the archive
type Config ¶
type Config struct { DB string `help:"the connection string for our database"` LogLevel string `help:"the log level, one of error, warn, info, debug"` SentryDSN string `help:"the sentry configuration to log errors to, if any"` S3Endpoint string `help:"the S3 endpoint we will write archives to"` S3Region string `help:"the S3 region we will write archives to"` S3Bucket string `help:"the S3 bucket we will write archives to"` S3DisableSSL bool `` /* 158-byte string literal not displayed */ S3ForcePathStyle bool `` /* 127-byte string literal not displayed */ AWSAccessKeyID string `help:"the access key id to use when authenticating S3"` AWSSecretAccessKey string `help:"the secret access key id to use when authenticating S3"` TempDir string `help:"directory where temporary archive files are written"` KeepFiles bool `help:"whether we should keep local archive files after upload (default false)"` UploadToS3 bool `help:"whether we should upload archive to S3"` ArchiveMessages bool `help:"whether we should archive messages"` ArchiveRuns bool `help:"whether we should archive runs"` Delete bool `help:"whether to delete messages and runs from the db after archival (default false)"` }
Config is our top level configuration object