Skip to content

Commit

Permalink
Added job option
Browse files Browse the repository at this point in the history
  • Loading branch information
pconstantinou committed Dec 22, 2023
1 parent d5bc4d1 commit 0582c3e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion neoq.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@ type Config struct {
PGConnectionTimeout time.Duration // the amount of time to wait for a connection to become available before timing out
}

// JobOptions
type JobOptions struct {
// Override allows the provided job to override an existing job with the same fingerprint
Override bool
}

// ConfigOption is a function that sets optional backend configuration
type ConfigOption func(c *Config)

// JobOption is a function that sets optional job enqueuing attributes
type JobOption func(o *JobOptions)

// NewConfig initiailizes a new Config with defaults
func NewConfig() *Config {
return &Config{
Expand All @@ -63,7 +72,7 @@ type BackendInitializer func(ctx context.Context, opts ...ConfigOption) (backend
// - [pkg/github.com/acaloiaro/neoq/backends/redis.RedisBackend]
type Neoq interface {
// Enqueue queues jobs to be executed asynchronously
Enqueue(ctx context.Context, job *jobs.Job) (jobID string, err error)
Enqueue(ctx context.Context, job *jobs.Job, opts ...JobOption) (jobID string, err error)

// Start starts processing jobs on the queue specified in the Handler
Start(ctx context.Context, h handler.Handler) (err error)
Expand Down Expand Up @@ -131,3 +140,11 @@ func WithLogLevel(level logging.LogLevel) ConfigOption {
c.LogLevel = level
}
}

// WithOverrideMatchingFingerprint will overwrite all the properties of a queued job if the fingerprint matches
// resetting the retries and updating the payload (if the fingerprint remains the same)
func WithOverrideMatchingFingerprint() JobOption {
return func(o *JobOptions) {
o.Override = true
}
}

0 comments on commit 0582c3e

Please sign in to comment.