Skip to content

Commit

Permalink
add function to disable cleanup worker
Browse files Browse the repository at this point in the history
  • Loading branch information
fsrv-xyz committed Dec 31, 2021
1 parent 25ea2d9 commit 56744a5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions main.go
Expand Up @@ -73,7 +73,7 @@ type Parameters struct {
S3BucketName string
S3UseSecurity bool
UploadLimitGB int64
EnableCleanupWorker bool
DisableCleanupWorker bool
}

var p Parameters
Expand All @@ -90,7 +90,7 @@ func init() {
flag.StringVar(&p.S3SecretKey, "s3.secret", "", "s3 secret key")
flag.StringVar(&p.S3BucketName, "s3.bucket", "", "s3 storage bucket")
flag.BoolVar(&p.S3UseSecurity, "s3.secure", true, "use tls for connection")
flag.BoolVar(&p.EnableCleanupWorker, "cleanup.enable", true, "manage object deletion process")
flag.BoolVar(&p.DisableCleanupWorker, "cleanup.disable", false, "manage object deletion process")
flag.StringVar(&p.DownloadLinkPrefix, "link.prefix", "http", "prepending stuff for download link")
flag.Parse()

Expand Down Expand Up @@ -193,21 +193,22 @@ func main() {
}
}()

// start worker processes
workerCount := -1
// create array of worker functions
var workers []func(context.Context, chan<- interface{})

// add workers to schedule array
workers = append(workers, c.HealthCheckWorker)
if p.EnableCleanupWorker {
if !p.DisableCleanupWorker {
workers = append(workers, c.CleanupWorker)
}

// start worker processes
workerCount := len(workers) - 1
for _, worker := range workers {
workerCount++
go worker(ctx, done)
}

// wait until cleanup worker is done
// wait until workers are done
var workersDone int
for range done {
if workersDone == workerCount {
Expand Down

0 comments on commit 56744a5

Please sign in to comment.