Skip to content

Commit

Permalink
wait 5 seconds on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Nov 4, 2024
1 parent 647802b commit aa9a51d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ issues:
- 'Magic number: 1\D '
- 'Magic number: 2\D '
- 'Magic number: 3\D '
- 'Magic number: 5\D '
- 'Magic number: 10\D '
- 'Magic number: 30\D '
- 'Magic number: 16\D '
Expand Down
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
This file documents the revision history for the Mod-Gearman-Worker-Go

next:
- change graceful shutdown timeout to 5seconds
- fix epn warnings perspective when using printf wrong

1.5.2 Wed Sep 4 11:03:28 CEST 2024
Expand Down
5 changes: 5 additions & 0 deletions pkg/modgearman/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var myCipher cipher.Block
type request struct {
typ string
resultQueue string
targetQueue string
hostName string
serviceDescription string
startTime float64
Expand All @@ -25,12 +26,14 @@ type request struct {
ballooning bool // flag wether this job has been put into background
Cancel func() // cancel current job
Canceled bool
rawRequest []byte
}

func (r *request) String() string {
return fmt.Sprintf(
"\n\t type: %s\n"+
"\t result_queue: %s\n"+
"\t target_queue: %s\n"+
"\t host_name: %s\n"+
"\t service_description: %s\n"+
"\t start_time: %f\n"+
Expand All @@ -40,6 +43,7 @@ func (r *request) String() string {
"\t command_line: %s\n\n",
r.typ,
r.resultQueue,
r.targetQueue,
r.hostName,
r.serviceDescription,
r.startTime,
Expand Down Expand Up @@ -109,6 +113,7 @@ func createReceived(input []byte) (*request, error) {
// then extract them and store them
result.typ = stringMap["type"]
result.resultQueue = stringMap["result_queue"]
result.targetQueue = stringMap["target_queue"]
result.hostName = stringMap["host_name"]
result.serviceDescription = stringMap["service_description"]
result.commandLine = stringMap["command_line"]
Expand Down
2 changes: 1 addition & 1 deletion pkg/modgearman/mainWorker.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ func (w *mainWorker) StopAllWorker(state MainStateType) {
}

// do not wait on shutdown via sigint
wait := 10 * time.Second
wait := 5 * time.Second
if state == Shutdown {
wait = 1 * time.Second
}
Expand Down
12 changes: 9 additions & 3 deletions pkg/modgearman/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ func (worker *worker) doWork(job libworker.Job) (res []byte, err error) {

worker.activeJobs++

received, err := decrypt((decodeBase64(string(job.Data()))), worker.config.encryption)
rawRequest := job.Data()
received, err := decrypt(decodeBase64(string(rawRequest)), worker.config.encryption)
if err != nil {
log.Errorf("decrypt failed: %w", err)
worker.activeJobs--

return nil, err
}
received.rawRequest = rawRequest
worker.mainWorker.tasks++

logJob(job, received, "incoming", nil)
Expand Down Expand Up @@ -291,9 +293,13 @@ func (worker *worker) Cancel() {
log.Debugf("worker %s cancling current jobs", worker.id)
worker.lock.Lock()
for _, j := range worker.jobs {
if j.Cancel != nil {
j.Cancel()
if j.Cancel == nil {
continue
}
j.Cancel()
}
if worker.worker != nil {
worker.worker.Close()
}
worker.lock.Unlock()
}
Expand Down

0 comments on commit aa9a51d

Please sign in to comment.