Class: Honker::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/honker.rb

Overview

A claimed unit of work. ‘payload` is the decoded JSON value (Hash, Array, etc.). `id`, `worker_id`, and `attempts` are metadata from the claim result.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue, row) ⇒ Job

Returns a new instance of Job.



292
293
294
295
296
297
298
299
# File 'lib/honker.rb', line 292

def initialize(queue, row)
  @queue = queue
  @id = row["id"]
  @queue_name = row["queue"]
  @payload = JSON.parse(row["payload"]) unless row["payload"].nil?
  @worker_id = row["worker_id"]
  @attempts = row["attempts"]
end

Instance Attribute Details

#attemptsObject (readonly)

Returns the value of attribute attempts.



290
291
292
# File 'lib/honker.rb', line 290

def attempts
  @attempts
end

#idObject (readonly)

Returns the value of attribute id.



290
291
292
# File 'lib/honker.rb', line 290

def id
  @id
end

#payloadObject (readonly)

Returns the value of attribute payload.



290
291
292
# File 'lib/honker.rb', line 290

def payload
  @payload
end

#queue_nameObject (readonly)

Returns the value of attribute queue_name.



290
291
292
# File 'lib/honker.rb', line 290

def queue_name
  @queue_name
end

#worker_idObject (readonly)

Returns the value of attribute worker_id.



290
291
292
# File 'lib/honker.rb', line 290

def worker_id
  @worker_id
end

Instance Method Details

#ackObject

DELETEs the row if the claim is still valid. Returns true/false.



302
303
304
# File 'lib/honker.rb', line 302

def ack
  @queue._ack(@id, @worker_id)
end

#fail(error: "") ⇒ Object

Unconditionally moves the claim to dead.



313
314
315
# File 'lib/honker.rb', line 313

def fail(error: "")
  @queue._fail(@id, @worker_id, error)
end

#heartbeat(extend_s:) ⇒ Object

Extend the claim’s visibility timeout.



318
319
320
# File 'lib/honker.rb', line 318

def heartbeat(extend_s:)
  @queue._heartbeat(@id, @worker_id, extend_s)
end

#retry(delay_s: 60, error: "") ⇒ Object

Returns the job to pending with a delay, or moves it to dead after max_attempts. Returns true iff the claim was valid.



308
309
310
# File 'lib/honker.rb', line 308

def retry(delay_s: 60, error: "")
  @queue._retry(@id, @worker_id, delay_s, error)
end