Class: River::JobRow
- Inherits:
-
Object
- Object
- River::JobRow
- Defined in:
- lib/job.rb
Overview
JobRow contains the properties of a job that are persisted to the database.
Instance Attribute Summary collapse
-
#args ⇒ Object
The job’s args as a hash decoded from JSON.
-
#attempt ⇒ Object
The attempt number of the job.
-
#attempted_at ⇒ Object
The time that the job was last worked.
-
#attempted_by ⇒ Object
The set of worker IDs that have worked this job.
-
#created_at ⇒ Object
When the job record was created.
-
#errors ⇒ Object
A set of errors that occurred when the job was worked, one for each attempt.
-
#finalized_at ⇒ Object
The time at which the job was “finalized”, meaning it was either completed successfully or errored for the last time such that it’ll no longer be retried.
-
#id ⇒ Object
ID of the job.
-
#kind ⇒ Object
Kind uniquely identifies the type of job and instructs which worker should work it.
-
#max_attempts ⇒ Object
The maximum number of attempts that the job will be tried before it errors for the last time and will no longer be worked.
-
#metadata ⇒ Object
Arbitrary metadata associated with the job.
-
#priority ⇒ Object
The priority of the job, with 1 being the highest priority and 4 being the lowest.
-
#queue ⇒ Object
The name of the queue where the job will be worked.
-
#scheduled_at ⇒ Object
When the job is scheduled to become available to be worked.
-
#state ⇒ Object
The state of job like
availableorcompleted. -
#tags ⇒ Object
Tags are an arbitrary list of keywords to add to the job.
-
#unique_key ⇒ Object
A unique key for the job within its kind that’s used for unique job insertions.
-
#unique_states ⇒ Object
A list of states that the job must be in to be considered for uniqueness.
Instance Method Summary collapse
-
#initialize(id:, args:, attempt:, created_at:, kind:, max_attempts:, metadata:, priority:, queue:, scheduled_at:, state:, attempted_at: nil, attempted_by: nil, errors: nil, finalized_at: nil, tags: nil, unique_key: nil, unique_states: nil) ⇒ JobRow
constructor
A new instance of JobRow.
Constructor Details
#initialize(id:, args:, attempt:, created_at:, kind:, max_attempts:, metadata:, priority:, queue:, scheduled_at:, state:, attempted_at: nil, attempted_by: nil, errors: nil, finalized_at: nil, tags: nil, unique_key: nil, unique_states: nil) ⇒ JobRow
Returns a new instance of JobRow.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/job.rb', line 120 def initialize( id:, args:, attempt:, created_at:, kind:, max_attempts:, metadata:, priority:, queue:, scheduled_at:, state:, # nullable/optional attempted_at: nil, attempted_by: nil, errors: nil, finalized_at: nil, tags: nil, unique_key: nil, unique_states: nil ) self.id = id self.args = args self.attempt = attempt self.attempted_at = attempted_at self.attempted_by = attempted_by self.created_at = created_at self.errors = errors self.finalized_at = finalized_at self.kind = kind self.max_attempts = max_attempts self. = self.priority = priority self.queue = queue self.scheduled_at = scheduled_at self.state = state self. = self.unique_key = unique_key self.unique_states = unique_states end |
Instance Attribute Details
#args ⇒ Object
The job’s args as a hash decoded from JSON.
45 46 47 |
# File 'lib/job.rb', line 45 def args @args end |
#attempt ⇒ Object
The attempt number of the job. Jobs are inserted at 0, the number is incremented to 1 the first time work its worked, and may increment further if it’s either snoozed or errors.
50 51 52 |
# File 'lib/job.rb', line 50 def attempt @attempt end |
#attempted_at ⇒ Object
The time that the job was last worked. Starts out as nil on a new insert.
54 55 56 |
# File 'lib/job.rb', line 54 def attempted_at @attempted_at end |
#attempted_by ⇒ Object
The set of worker IDs that have worked this job. A worker ID differs between different programs, but is shared by all executors within any given one. (i.e. Different Go processes have different IDs, but IDs are shared within any given process.) A process generates a new ID based on host and current time when it starts up.
61 62 63 |
# File 'lib/job.rb', line 61 def attempted_by @attempted_by end |
#created_at ⇒ Object
When the job record was created.
64 65 66 |
# File 'lib/job.rb', line 64 def created_at @created_at end |
#errors ⇒ Object
A set of errors that occurred when the job was worked, one for each attempt. Ordered from earliest error to the latest error.
68 69 70 |
# File 'lib/job.rb', line 68 def errors @errors end |
#finalized_at ⇒ Object
The time at which the job was “finalized”, meaning it was either completed successfully or errored for the last time such that it’ll no longer be retried.
73 74 75 |
# File 'lib/job.rb', line 73 def finalized_at @finalized_at end |
#id ⇒ Object
ID of the job. Generated as part of a Postgres sequence and generally ascending in nature, but there may be gaps in it as transactions roll back.
42 43 44 |
# File 'lib/job.rb', line 42 def id @id end |
#kind ⇒ Object
Kind uniquely identifies the type of job and instructs which worker should work it. It is set at insertion time via #kind on job args.
77 78 79 |
# File 'lib/job.rb', line 77 def kind @kind end |
#max_attempts ⇒ Object
The maximum number of attempts that the job will be tried before it errors for the last time and will no longer be worked.
81 82 83 |
# File 'lib/job.rb', line 81 def max_attempts @max_attempts end |
#metadata ⇒ Object
Arbitrary metadata associated with the job.
84 85 86 |
# File 'lib/job.rb', line 84 def @metadata end |
#priority ⇒ Object
The priority of the job, with 1 being the highest priority and 4 being the lowest. When fetching available jobs to work, the highest priority jobs will always be fetched before any lower priority jobs are fetched. Note that if your workers are swamped with more high-priority jobs then they can handle, lower priority jobs may not be fetched.
91 92 93 |
# File 'lib/job.rb', line 91 def priority @priority end |
#queue ⇒ Object
The name of the queue where the job will be worked. Queues can be configured independently and be used to isolate jobs.
95 96 97 |
# File 'lib/job.rb', line 95 def queue @queue end |
#scheduled_at ⇒ Object
When the job is scheduled to become available to be worked. Jobs default to running immediately, but may be scheduled for the future when they’re inserted. They may also be scheduled for later because they were snoozed or because they errored and have additional retry attempts remaining.
101 102 103 |
# File 'lib/job.rb', line 101 def scheduled_at @scheduled_at end |
#state ⇒ Object
The state of job like available or completed. Jobs are available when they’re first inserted.
105 106 107 |
# File 'lib/job.rb', line 105 def state @state end |
#tags ⇒ Object
Tags are an arbitrary list of keywords to add to the job. They have no functional behavior and are meant entirely as a user-specified construct to help group and categorize jobs.
110 111 112 |
# File 'lib/job.rb', line 110 def @tags end |
#unique_key ⇒ Object
A unique key for the job within its kind that’s used for unique job insertions. It’s generated by hashing an inserted job’s unique opts configuration.
115 116 117 |
# File 'lib/job.rb', line 115 def unique_key @unique_key end |
#unique_states ⇒ Object
A list of states that the job must be in to be considered for uniqueness.
118 119 120 |
# File 'lib/job.rb', line 118 def unique_states @unique_states end |