Class: JobWorkflow::TaskContext

Inherits:
Object
  • Object
show all
Defined in:
lib/job_workflow/task_context.rb

Constant Summary collapse

NULL_VALUE =

: 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


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_runObject

: bool



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

def dry_run
  @dry_run
end

#indexObject

: Integer



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

def index
  @index
end

#parent_job_idObject

: String?



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

def parent_job_id
  @parent_job_id
end

#retry_countObject

: Integer



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

def retry_count
  @retry_count
end

#taskObject

: Task?



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

def task
  @task
end

#valueObject

: untyped



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

def value
  @value
end

Class Method Details

.deserialize(hash) ⇒ Object

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



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

#serializeObject

: () -> 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