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.



418
419
420
421
422
423
424
425
# File 'lib/honker.rb', line 418

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.



416
417
418
# File 'lib/honker.rb', line 416

def attempts
  @attempts
end

#idObject (readonly)

Returns the value of attribute id.



416
417
418
# File 'lib/honker.rb', line 416

def id
  @id
end

#payloadObject (readonly)

Returns the value of attribute payload.



416
417
418
# File 'lib/honker.rb', line 416

def payload
  @payload
end

#queue_nameObject (readonly)

Returns the value of attribute queue_name.



416
417
418
# File 'lib/honker.rb', line 416

def queue_name
  @queue_name
end

#worker_idObject (readonly)

Returns the value of attribute worker_id.



416
417
418
# File 'lib/honker.rb', line 416

def worker_id
  @worker_id
end

Instance Method Details

#ackObject

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



428
429
430
# File 'lib/honker.rb', line 428

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

#fail(error: "") ⇒ Object

Unconditionally moves the claim to dead.



439
440
441
# File 'lib/honker.rb', line 439

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

#heartbeat(extend_s:) ⇒ Object

Extend the claim’s visibility timeout.



444
445
446
# File 'lib/honker.rb', line 444

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.



434
435
436
# File 'lib/honker.rb', line 434

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