Class: Zizq::Resources::Job

Inherits:
JobTemplate show all
Defined in:
lib/zizq/resources/job.rb

Overview

Typed wrapper around a job response hash.

Inherits template fields (type, queue, priority, payload, backoff, retention, unique_key, unique_while) from JobTemplate and adds lifecycle fields and action methods.

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from JobTemplate

#backoff, #payload, #priority, #queue, #retention, #retry_limit, #type, #unique_key, #unique_while

Methods inherited from Resource

#initialize, #inspect, #to_h

Constructor Details

This class inherits a constructor from Zizq::Resources::Resource

Instance Method Details

#attemptsObject

: () -> Integer



18
# File 'lib/zizq/resources/job.rb', line 18

def attempts    = @data["attempts"]    #: () -> Integer

#complete!Object

Mark this job as successfully completed.



35
36
37
# File 'lib/zizq/resources/job.rb', line 35

def complete! #: () -> nil
  @client.report_success(id)
end

#completed_atObject

: () -> Float?



21
# File 'lib/zizq/resources/job.rb', line 21

def completed_at  = ms_to_seconds(@data["completed_at"])  #: () -> Float?

#deleteObject

Delete this job.



54
55
56
# File 'lib/zizq/resources/job.rb', line 54

def delete
  @client.delete_job(id)
end

#dequeued_atObject

: () -> Float?



19
# File 'lib/zizq/resources/job.rb', line 19

def dequeued_at = ms_to_seconds(@data["dequeued_at"]) #: () -> Float?

#duplicate?Boolean

: () -> bool

Returns:

  • (Boolean)


22
# File 'lib/zizq/resources/job.rb', line 22

def duplicate?    = @data["duplicate"] == true #: () -> bool

#errors(order: nil, limit: nil, page_size: nil) ⇒ Object

Fetch the error history for this job.



30
31
32
# File 'lib/zizq/resources/job.rb', line 30

def errors(order: nil, limit: nil, page_size: nil)
  ErrorEnumerator.new(id, order:, limit:, page_size:)
end

#fail!(message:, error_type: nil, backtrace: nil, retry_at: nil, kill: false) ⇒ Object

Report this job as failed.



47
48
49
# File 'lib/zizq/resources/job.rb', line 47

def fail!(message:, error_type: nil, backtrace: nil, retry_at: nil, kill: false)
  @client.report_failure(id, message:, error_type:, backtrace:, retry_at:, kill:)
end

#failed_atObject

: () -> Float?



20
# File 'lib/zizq/resources/job.rb', line 20

def failed_at     = ms_to_seconds(@data["failed_at"])     #: () -> Float?

#idObject

: () -> String



15
# File 'lib/zizq/resources/job.rb', line 15

def id          = @data["id"]          #: () -> String

#ready_atObject

: () -> Float?



17
# File 'lib/zizq/resources/job.rb', line 17

def ready_at    = ms_to_seconds(@data["ready_at"])    #: () -> Float?

#statusObject

: () -> String



16
# File 'lib/zizq/resources/job.rb', line 16

def status      = @data["status"]      #: () -> String

#update(queue: Zizq::UNCHANGED, priority: Zizq::UNCHANGED, ready_at: Zizq::UNCHANGED, retry_limit: Zizq::UNCHANGED, backoff: Zizq::UNCHANGED, retention: Zizq::UNCHANGED) ⇒ Object

Update this job’s mutable fields.

Returns the updated job.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/zizq/resources/job.rb', line 69

def update(queue: Zizq::UNCHANGED,
           priority: Zizq::UNCHANGED,
           ready_at: Zizq::UNCHANGED,
           retry_limit: Zizq::UNCHANGED,
           backoff: Zizq::UNCHANGED,
           retention: Zizq::UNCHANGED)
  job = @client.update_job(
    id,
    queue:,
    priority:,
    ready_at:,
    retry_limit:,
    backoff:,
    retention:
  )

  # Make sure this job's fields are updated.
  @data.merge!(job.to_h)

  job
end