Class: Zizq::Resources::Job

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

Overview

Typed wrapper around a job response hash.

Exposes named accessor methods with Ruby-idiomatic types (fractional seconds instead of milliseconds) and link methods that follow related resources through the Client.

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize, #inspect, #to_h

Constructor Details

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

Instance Method Details

#attemptsObject

: () -> Integer



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

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

#backoffObject

Backoff configuration converted from the wire format (ms) to the Ruby-idiomatic format (seconds), matching the Zizq::backoff type.



33
34
35
36
37
38
39
40
41
42
# File 'lib/zizq/resources/job.rb', line 33

def backoff #: () -> Zizq::backoff?
  raw = @data["backoff"]
  return nil unless raw

  {
    exponent: raw["exponent"].to_f,
    base: raw["base_ms"] / 1000.0,
    jitter: raw["jitter_ms"] / 1000.0
  }
end

#complete!Object

Mark this job as successfully completed.



67
68
69
# File 'lib/zizq/resources/job.rb', line 67

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

#completed_atObject

: () -> Float?



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

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

#deleteObject

Delete this job.



86
87
88
# File 'lib/zizq/resources/job.rb', line 86

def delete
  @client.delete_job(id)
end

#dequeued_atObject

: () -> Float?



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

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

#duplicate?Boolean

: () -> bool

Returns:

  • (Boolean)


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

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

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

Fetch the error history for this job.



62
63
64
# File 'lib/zizq/resources/job.rb', line 62

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.



79
80
81
# File 'lib/zizq/resources/job.rb', line 79

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?



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

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

#payloadObject

: () -> Hash[String, untyped]?



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

def payload     = @data["payload"]     #: () -> Hash[String, untyped]?

#priorityObject

: () -> Integer



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

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

#queueObject

: () -> String



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

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

#ready_atObject

: () -> Float?



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

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

#retentionObject

Retention configuration converted from the wire format (ms) to the Ruby-idiomatic format (seconds), matching the Zizq::retention type.



46
47
48
49
50
51
52
53
54
# File 'lib/zizq/resources/job.rb', line 46

def retention #: () -> Zizq::retention?
  raw = @data["retention"]
  return nil unless raw

  result = {} #: Hash[Symbol, Float]
  result[:completed] = raw["completed_ms"] / 1000.0 if raw["completed_ms"]
  result[:dead] = raw["dead_ms"] / 1000.0 if raw["dead_ms"]
  result
end

#retry_limitObject

: () -> Integer?



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

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

#statusObject

: () -> String



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

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

#typeObject

: () -> String



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

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

#unique_keyObject

: () -> String?



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

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

#unique_whileObject

: () -> Zizq::unique_scope?



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

def unique_while  = @data["unique_while"]&.to_sym #: () -> Zizq::unique_scope?

#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.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/zizq/resources/job.rb', line 101

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