Documentation
¶
Index ¶
- Constants
- func BuildMonthlyArchive(ctx context.Context, conf *Config, s3Client s3iface.S3API, archives []*Archive, ...) error
- func CreateArchiveFile(ctx context.Context, db *sqlx.DB, archive *Archive, archivePath string) error
- func DeleteArchiveFile(archive *Archive) error
- func EnsureTempArchiveDirectory(path string) error
- func GetS3File(ctx context.Context, s3Client s3iface.S3API, fileURL string) (io.ReadCloser, error)
- func NewS3Client(config *Config) (s3iface.S3API, error)
- func PutS3File(s3Client s3iface.S3API, bucket string, path string, contentType string, ...) (string, error)
- func TestS3(s3Client s3iface.S3API, bucket string) error
- func UploadArchive(ctx context.Context, s3Client s3iface.S3API, bucket string, archive *Archive) error
- func WithAcceptEncoding(e string) request.Option
- func WriteArchiveToDB(ctx context.Context, db *sqlx.DB, archive *Archive) error
- type Archive
- func ArchiveOrg(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, ...) ([]*Archive, error)
- func BuildOrgDailyArchives(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, ...) ([]*Archive, error)
- func BuildOrgMonthlyArchives(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, ...) ([]*Archive, error)
- func GetCurrentArchives(ctx context.Context, db *sqlx.DB, org Org, archiveType ArchiveType) ([]*Archive, error)
- func GetMissingDayArchives(archives []*Archive, now time.Time, org Org, archiveType ArchiveType) ([]*Archive, error)
- func GetMissingMonthArchives(archives []*Archive, now time.Time, org Org, archiveType ArchiveType) ([]*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 BuildMonthlyArchive ¶ added in v0.0.6
func BuildMonthlyArchive(ctx context.Context, conf *Config, s3Client s3iface.S3API, archives []*Archive, month *Archive, now time.Time, org Org, archiveType ArchiveType) error
BuildMonthlyArchive 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 EnsureTempArchiveDirectory ¶ added in v0.0.6
EnsureTempArchiveDirectory checks that we can write to our archive directory, creating it first if needbe
func GetS3File ¶ added in v0.0.6
GetS3File return an io.ReadCloser for the passed in bucket and path
func NewS3Client ¶ added in v0.0.6
NewS3Client creates a new s3 client from the passed in config, testing it as necessary
func PutS3File ¶ added in v0.0.6
func PutS3File(s3Client s3iface.S3API, bucket string, path string, contentType string, contentEncoding string, filename string, md5 string) (string, error)
PutS3File writes the passed in file to the bucket with the passed in content type
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
func WithAcceptEncoding ¶ added in v0.0.6
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"` IsPurged bool `db:"is_purged"` Rollup *int `db:"rollup_id"` Org Org ArchiveFile string Dailies []*Archive }
Archive represents the model for an archive
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, error)
ArchiveOrg looks for any missing archives for the passed in org, creating and uploading them as necessary, returning the created archives
func BuildOrgDailyArchives ¶ added in v0.0.6
func BuildOrgDailyArchives(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, s3Client s3iface.S3API, org Org, archiveType ArchiveType) ([]*Archive, error)
BuildOrgDailyArchives builds all the montly archives for the passid in org
func BuildOrgMonthlyArchives ¶ added in v0.0.6
func BuildOrgMonthlyArchives(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, s3Client s3iface.S3API, org Org, archiveType ArchiveType) ([]*Archive, error)
BuildOrgMonthlyArchives builds all the montly archives for the passid in org
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 GetMissingDayArchives ¶ added in v0.0.6
func GetMissingDayArchives(archives []*Archive, now time.Time, org Org, archiveType ArchiveType) ([]*Archive, error)
GetMissingDayArchives calculates what archives need to be generated for the passed in org this is calculated per day
func GetMissingMonthArchives ¶ added in v0.0.6
func GetMissingMonthArchives(archives []*Archive, now time.Time, org Org, archiveType ArchiveType) ([]*Archive, error)
GetMissingMonthArchives gets which archives need to be rolled up in the set that has been passed in
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"` DeleteAfterUpload bool `help:"whether we should delete temporary archive file"` 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"` }
Config is our top level configuration object