Class: JobWorkflow::Task

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_name:, name:, block:, each: nil, enqueue: nil, output: {}, depends_on: [], condition: ->(_ctx) { true }, task_retry: 0, throttle: {}, timeout: nil, dependency_wait: {}, dry_run: false) ⇒ Task

rubocop:disable Metrics/ParameterLists, Metrics/MethodLength : (

  job_name: String,
  name: Symbol,
  block: ^(untyped) -> void,
  ?each: ^(Context) -> untyped,
  ?enqueue: true | false | ^(Context) -> bool | Hash[Symbol, untyped],
  ?output: Hash[Symbol, String],
  ?depends_on: Array[Symbol],
  condition: ^(Context) -> bool,
  ?task_retry: Integer | Hash[Symbol, untyped],
  ?throttle: Integer | Hash[Symbol, untyped],
  ?timeout: Numeric?,
  ?dependency_wait: Hash[Symbol, untyped],
  ?dry_run: bool | ^(Context) -> bool
) -> void


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/job_workflow/task.rb', line 34

def initialize(
  job_name:,
  name:,
  block:,
  each: nil,
  enqueue: nil,
  output: {},
  depends_on: [],
  condition: ->(_ctx) { true },
  task_retry: 0,
  throttle: {},
  timeout: nil,
  dependency_wait: {},
  dry_run: false
)
  @job_name = job_name
  @name = name
  @block = block
  @each = each
  @enqueue = TaskEnqueue.from_primitive_value(enqueue)
  @output = output.map { |name, type| OutputDef.new(name:, type:) }
  @depends_on = depends_on
  @condition = condition
  @task_retry = TaskRetry.from_primitive_value(task_retry)
  @throttle = TaskThrottle.from_primitive_value_with_task(value: throttle, task: self)
  @timeout = timeout
  @dependency_wait = TaskDependencyWait.from_primitive_value(dependency_wait)
  @dry_run_config = DryRunConfig.from_primitive_value(dry_run)
end

Instance Attribute Details

#blockObject (readonly)

: ^(untyped) -> void



6
7
8
# File 'lib/job_workflow/task.rb', line 6

def block
  @block
end

#conditionObject (readonly)

: ^(Context) -> bool



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

def condition
  @condition
end

#dependency_waitObject (readonly)

: TaskDependencyWait



15
16
17
# File 'lib/job_workflow/task.rb', line 15

def dependency_wait
  @dependency_wait
end

#depends_onObject (readonly)

: Array



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

def depends_on
  @depends_on
end

#dry_run_configObject (readonly)

: DryRunConfig



16
17
18
# File 'lib/job_workflow/task.rb', line 16

def dry_run_config
  @dry_run_config
end

#eachObject (readonly)

: ^(Context) -> untyped



7
8
9
# File 'lib/job_workflow/task.rb', line 7

def each
  @each
end

#enqueueObject (readonly)

: TaskEnqueue



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

def enqueue
  @enqueue
end

#job_nameObject (readonly)

: String



5
6
7
# File 'lib/job_workflow/task.rb', line 5

def job_name
  @job_name
end

#outputObject (readonly)

: Array



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

def output
  @output
end

#task_retryObject (readonly)

: TaskRetry



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

def task_retry
  @task_retry
end

#throttleObject (readonly)

: TaskThrottle



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

def throttle
  @throttle
end

#timeoutObject (readonly)

: Numeric?



14
15
16
# File 'lib/job_workflow/task.rb', line 14

def timeout
  @timeout
end

Instance Method Details

#task_nameObject

: () -> Symbol



66
67
68
# File 'lib/job_workflow/task.rb', line 66

def task_name
  name
end

#throttle_prefix_keyObject

: () -> String



71
72
73
# File 'lib/job_workflow/task.rb', line 71

def throttle_prefix_key
  "#{job_name}:#{task_name}"
end