forked from benmanns/goworker
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
goworker: Added 'MaxAgeRetries' option to the Goworker
This option is useful to automatically remove retried failed jobs from the 'failed' queue that exceede that duration, this check will be done every 1m. Also changed the 'failed.FailedAt' and added 'failed.RetriedAt' and switched them to type string. The main reason is that the Ruby lib is setting those values in an specific format and Ruby can read multiple formats into one, but GO cannot and we need to actually use the same ones or the unmarshaler does not work so I decided to switch them to 'string' and add helpers to set/get the values that will directly convert them. All the logic has more or less been ported from the Ruby version, on how to remove failed jobs and how the data is stored, as the 'MaxAgeRetries' is something unique from this GO version
- Loading branch information
Showing
5 changed files
with
130 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,31 @@ | ||
package goworker | ||
|
||
import ( | ||
"time" | ||
import "time" | ||
|
||
const ( | ||
retriedAtLayout = "2006/01/02 15:04:05" | ||
failedAtLayout = "2006/01/02 15:04:05 -07:00" | ||
) | ||
|
||
type failure struct { | ||
FailedAt time.Time `json:"failed_at"` | ||
Payload Payload `json:"payload"` | ||
Exception string `json:"exception"` | ||
Error string `json:"error"` | ||
Backtrace []string `json:"backtrace"` | ||
Worker *worker `json:"worker"` | ||
Queue string `json:"queue"` | ||
FailedAt string `json:"failed_at"` | ||
Payload Payload `json:"payload"` | ||
Exception string `json:"exception"` | ||
Error string `json:"error"` | ||
Backtrace []string `json:"backtrace"` | ||
Worker *worker `json:"worker"` | ||
Queue string `json:"queue"` | ||
RetriedAt string `json:"retried_at"` | ||
} | ||
|
||
func (f *failure) GetRetriedAtTime() (time.Time, error) { | ||
if f.RetriedAt == "" { | ||
return time.Time{}, nil | ||
} | ||
|
||
return time.Parse(retriedAtLayout, f.RetriedAt) | ||
} | ||
|
||
func (f *failure) SetFailedAt(t time.Time) { | ||
f.FailedAt = t.Format(failedAtLayout) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters