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.



283
284
285
286
287
288
289
290
# File 'lib/honker.rb', line 283

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.



281
282
283
# File 'lib/honker.rb', line 281

def attempts
  @attempts
end

#idObject (readonly)

Returns the value of attribute id.



281
282
283
# File 'lib/honker.rb', line 281

def id
  @id
end

#payloadObject (readonly)

Returns the value of attribute payload.



281
282
283
# File 'lib/honker.rb', line 281

def payload
  @payload
end

#queue_nameObject (readonly)

Returns the value of attribute queue_name.



281
282
283
# File 'lib/honker.rb', line 281

def queue_name
  @queue_name
end

#worker_idObject (readonly)

Returns the value of attribute worker_id.



281
282
283
# File 'lib/honker.rb', line 281

def worker_id
  @worker_id
end

Instance Method Details

#ackObject

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



293
294
295
# File 'lib/honker.rb', line 293

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

#fail(error: "") ⇒ Object

Unconditionally moves the claim to dead.



304
305
306
# File 'lib/honker.rb', line 304

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

#heartbeat(extend_s:) ⇒ Object

Extend the claim’s visibility timeout.



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

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.



299
300
301
# File 'lib/honker.rb', line 299

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