This commit is contained in:
sujit
2025-10-01 12:31:58 +05:45
parent 0340774cfe
commit 8ec9474bdc
20 changed files with 5015 additions and 1123 deletions

19
task.go
View File

@@ -115,8 +115,9 @@ type Task struct {
CreatedAt time.Time `json:"created_at"`
ProcessedAt time.Time `json:"processed_at"`
Expiry time.Time `json:"expiry"`
Error error `json:"-"` // Don't serialize errors directly
ErrorMsg string `json:"error,omitempty"` // Serialize error message if present
DeferUntil time.Time `json:"defer_until,omitempty"` // NEW: For deferred task execution
Error error `json:"-"` // Don't serialize errors directly
ErrorMsg string `json:"error,omitempty"` // Serialize error message if present
ID string `json:"id"`
Topic string `json:"topic"`
Status Status `json:"status"` // Use Status type instead of string
@@ -232,6 +233,20 @@ func WithTTL(ttl time.Duration) TaskOption {
}
}
// TaskOption for deferring task execution until a specific time
func WithDeferUntil(deferUntil time.Time) TaskOption {
return func(t *Task) {
t.DeferUntil = deferUntil
}
}
// TaskOption for deferring task execution for a specific duration
func WithDeferDuration(duration time.Duration) TaskOption {
return func(t *Task) {
t.DeferUntil = time.Now().Add(duration)
}
}
// TaskOption for adding tags
func WithTags(tags map[string]string) TaskOption {
return func(t *Task) {