Class: Zizq::Resources::Job

Inherits:
JobTemplate show all
Defined in:
lib/zizq/resources/job.rb,
sig/generated/zizq/resources/job.rbs

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, #batch, #payload, #priority, #queue, #retention, #retry_limit, #type, #unique_key, #unique_while

Methods inherited from Resource

#initialize, #inspect, #ms_to_seconds, #to_h

Constructor Details

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

Instance Method Details

#attemptsObject

Signature:

  • () -> Integer

Returns:

  • (Object)


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

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

#complete!Object

Mark this job as successfully completed.

Returns:

  • (Object)


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

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

#completed_atObject

Signature:

  • () -> Float?

Returns:

  • (Object)


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

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

#deletevoid

This method returns an undefined value.

Delete this job.

RBS:

  • return: void



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

def delete
  @client.delete_job(id)
end

#dequeued_atObject

Signature:

  • () -> Float?

Returns:

  • (Object)


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

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

#duplicate?Boolean

Signature:

  • () -> 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) ⇒ ErrorEnumerator

Fetch the error history for this job.

RBS:

  • order: Zizq::sort_direction?

  • limit: Integer?

  • page_size: Integer?

  • return: ErrorEnumerator

Parameters:

  • order: (Zizq::sort_direction, nil) (defaults to: nil)
  • limit: (Integer, nil) (defaults to: nil)
  • page_size: (Integer, nil) (defaults to: nil)

Returns:



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

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) ⇒ Job

Report this job as failed.

RBS:

  • message: String

  • error_type: String?

  • backtrace: String?

  • retry_at: Float?

  • kill: bool

  • return: Job

Parameters:

  • message: (String)
  • error_type: (String, nil) (defaults to: nil)
  • backtrace: (String, nil) (defaults to: nil)
  • retry_at: (Float, nil) (defaults to: nil)
  • kill: (Boolean) (defaults to: false)

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/zizq/resources/job.rb', line 48

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

Signature:

  • () -> Float?

Returns:

  • (Object)


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

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

#folded?Boolean

Signature:

  • () -> bool

Returns:

  • (Boolean)


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

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

#idObject

Signature:

  • () -> String

Returns:

  • (Object)


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

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

#ready_atObject

Signature:

  • () -> Float?

Returns:

  • (Object)


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

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

#statusObject

Signature:

  • () -> String

Returns:

  • (Object)


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) ⇒ Job

Update this job's mutable fields.

Returns the updated job.

RBS:

  • queue: (String | singleton(Zizq::UNCHANGED))?

  • priority: (Integer | singleton(Zizq::UNCHANGED))?

  • ready_at: (Zizq::to_f | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?

  • retry_limit: (Integer | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?

  • backoff: (Zizq::backoff | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?

  • retention: (Zizq::retention | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?

  • return: Job

Parameters:

Returns:



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/zizq/resources/job.rb', line 83

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