Class: River::UniqueOpts
- Inherits:
-
Object
- Object
- River::UniqueOpts
- Defined in:
- lib/insert_opts.rb
Overview
Parameters for uniqueness for a job.
If all properties are nil, no uniqueness at is enforced. As each property is initialized, it’s added as a dimension on the uniqueness matrix, and with any property on, the job’s kind always counts toward uniqueness.
So for example, if only #by_queue is on, then for the given job kind, only a single instance is allowed in any given queue, regardless of other properties on the job. If both #by_args and #by_queue are on, then for the given job kind, a single instance is allowed for each combination of args and queues. If either args or queue is changed on a new job, it’s allowed to be inserted as a new job.
Instance Attribute Summary collapse
-
#by_args ⇒ Object
Indicates that uniqueness should be enforced for any specific instance of encoded args for a job.
-
#by_period ⇒ Object
Defines uniqueness within a given period.
-
#by_queue ⇒ Object
Indicates that uniqueness should be enforced within each queue.
-
#by_state ⇒ Object
Indicates that uniqueness should be enforced across any of the states in the given set.
-
#exclude_kind ⇒ Object
Indicates that the job kind should not be considered for uniqueness.
Instance Method Summary collapse
-
#initialize(by_args: nil, by_period: nil, by_queue: nil, by_state: nil, exclude_kind: nil) ⇒ UniqueOpts
constructor
A new instance of UniqueOpts.
Constructor Details
#initialize(by_args: nil, by_period: nil, by_queue: nil, by_state: nil, exclude_kind: nil) ⇒ UniqueOpts
Returns a new instance of UniqueOpts.
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/insert_opts.rb', line 126 def initialize( by_args: nil, by_period: nil, by_queue: nil, by_state: nil, exclude_kind: nil ) self.by_args = by_args self.by_period = by_period self.by_queue = by_queue self.by_state = by_state self.exclude_kind = exclude_kind end |
Instance Attribute Details
#by_args ⇒ Object
Indicates that uniqueness should be enforced for any specific instance of encoded args for a job.
Default is false, meaning that as long as any other unique property is enabled, uniqueness will be enforced for a kind regardless of input args.
81 82 83 |
# File 'lib/insert_opts.rb', line 81 def by_args @by_args end |
#by_period ⇒ Object
Defines uniqueness within a given period. On an insert time is rounded down to the nearest multiple of the given period, and a job is only inserted if there isn’t an existing job that will run between then and the next multiple of the period.
The period should be specified in seconds. So a job that’s unique every 15 minute period would have a value of 900.
Default is no unique period, meaning that as long as any other unique property is enabled, uniqueness will be enforced across all jobs of the kind in the database, regardless of when they were scheduled.
94 95 96 |
# File 'lib/insert_opts.rb', line 94 def by_period @by_period end |
#by_queue ⇒ Object
Indicates that uniqueness should be enforced within each queue.
Default is false, meaning that as long as any other unique property is enabled, uniqueness will be enforced for a kind across all queues.
100 101 102 |
# File 'lib/insert_opts.rb', line 100 def by_queue @by_queue end |
#by_state ⇒ Object
Indicates that uniqueness should be enforced across any of the states in the given set. For example, if the given states were ‘(scheduled, running)` then a new job could be inserted even if one of the same kind was already being worked by the queue (new jobs are inserted as available).
Unlike other unique options, ByState gets a default when it’s not set for user convenience. The default is equivalent to:
by_state: [River::JOB_STATE_AVAILABLE, River::JOB_STATE_COMPLETED, River::JOB_STATE_PENDING, River::JOB_STATE_RUNNING, River::JOB_STATE_RETRYABLE, River::JOB_STATE_SCHEDULED]
With this setting, any jobs of the same kind that have been completed or discarded, but not yet cleaned out by the system, won’t count towards the uniqueness of a new insert.
The pending, scheduled, available, and running states are required when customizing this list.
119 120 121 |
# File 'lib/insert_opts.rb', line 119 def by_state @by_state end |
#exclude_kind ⇒ Object
Indicates that the job kind should not be considered for uniqueness. This is useful when you want to enforce uniqueness based on other properties across multiple worker types.
124 125 126 |
# File 'lib/insert_opts.rb', line 124 def exclude_kind @exclude_kind end |