Class: JobWorkflow::TaskContext

Inherits:
Object
  • Object
show all
Defined in:
lib/job_workflow/task_context.rb,
sig/generated/job_workflow/task_context.rbs

Constant Summary collapse

NULL_VALUE =

Signature:

  • nil

Returns:

  • (nil)
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task: nil, parent_job_id: nil, index: 0, value: nil, retry_count: 0, dry_run: false) ⇒ TaskContext

: ( ?task: Task?, ?parent_job_id: String?, ?index: Integer, ?value: untyped, ?retry_count: Integer, ?dry_run: bool ) -> void

Parameters:

  • task: (Task, nil) (defaults to: nil)
  • parent_job_id: (String, nil) (defaults to: nil)
  • index: (Integer) (defaults to: 0)
  • value: (Object) (defaults to: nil)
  • retry_count: (Integer) (defaults to: 0)
  • dry_run: (Boolean) (defaults to: false)


36
37
38
39
40
41
42
43
# File 'lib/job_workflow/task_context.rb', line 36

def initialize(task: nil, parent_job_id: nil, index: 0, value: nil, retry_count: 0, dry_run: false) # rubocop:disable Metrics/ParameterLists
  self.task = task
  self.parent_job_id = parent_job_id
  self.index = index
  self.value = value
  self.retry_count = retry_count
  self.dry_run = dry_run
end

Instance Attribute Details

#dry_runBoolean

Signature:

  • bool

Returns:

  • (Boolean)


13
14
15
# File 'lib/job_workflow/task_context.rb', line 13

def dry_run
  @dry_run
end

#indexInteger

Signature:

  • Integer

Returns:

  • (Integer)


10
11
12
# File 'lib/job_workflow/task_context.rb', line 10

def index
  @index
end

#parent_job_idString?

Signature:

  • String?

Returns:

  • (String, nil)


9
10
11
# File 'lib/job_workflow/task_context.rb', line 9

def parent_job_id
  @parent_job_id
end

#retry_countInteger

Signature:

  • Integer

Returns:

  • (Integer)


12
13
14
# File 'lib/job_workflow/task_context.rb', line 12

def retry_count
  @retry_count
end

#taskTask?

Signature:

  • Task?

Returns:



8
9
10
# File 'lib/job_workflow/task_context.rb', line 8

def task
  @task
end

#valueObject

Signature:

  • untyped

Returns:

  • (Object)


11
12
13
# File 'lib/job_workflow/task_context.rb', line 11

def value
  @value
end

Class Method Details

.deserialize(hash) ⇒ TaskContext

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

Parameters:

  • (Hash[String, untyped])

Returns:



17
18
19
20
21
22
23
24
25
# File 'lib/job_workflow/task_context.rb', line 17

def deserialize(hash)
  new(
    task: hash["task"],
    parent_job_id: hash["parent_job_id"],
    index: hash["index"],
    value: ActiveJob::Arguments.deserialize([hash["value"]]).first,
    retry_count: hash.fetch("retry_count", 0)
  )
end

Instance Method Details

#enabled?Boolean

: () -> bool

Returns:

  • (Boolean)


46
47
48
# File 'lib/job_workflow/task_context.rb', line 46

def enabled?
  !parent_job_id.nil?
end

#serializeHash[String, untyped]

: () -> Hash[String, untyped]

Returns:

  • (Hash[String, untyped])


51
52
53
54
55
56
57
58
59
# File 'lib/job_workflow/task_context.rb', line 51

def serialize
  {
    "task_name" => task&.task_name,
    "parent_job_id" => parent_job_id,
    "index" => index,
    "value" => ActiveJob::Arguments.serialize([value]).first,
    "retry_count" => retry_count
  }
end