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.



536
537
538
539
540
541
542
543
# File 'lib/honker.rb', line 536

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.



534
535
536
# File 'lib/honker.rb', line 534

def attempts
  @attempts
end

#idObject (readonly)

Returns the value of attribute id.



534
535
536
# File 'lib/honker.rb', line 534

def id
  @id
end

#payloadObject (readonly)

Returns the value of attribute payload.



534
535
536
# File 'lib/honker.rb', line 534

def payload
  @payload
end

#queue_nameObject (readonly)

Returns the value of attribute queue_name.



534
535
536
# File 'lib/honker.rb', line 534

def queue_name
  @queue_name
end

#worker_idObject (readonly)

Returns the value of attribute worker_id.



534
535
536
# File 'lib/honker.rb', line 534

def worker_id
  @worker_id
end

Instance Method Details

#ackObject

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



546
547
548
# File 'lib/honker.rb', line 546

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

#fail(error: "") ⇒ Object

Unconditionally moves the claim to dead.



557
558
559
# File 'lib/honker.rb', line 557

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

#heartbeat(extend_s:) ⇒ Object

Extend the claim's visibility timeout.



562
563
564
# File 'lib/honker.rb', line 562

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.



552
553
554
# File 'lib/honker.rb', line 552

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