Class: JobWorkflow::Task

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

Constant Summary collapse

DEFAULT_EACH =
->(_ctx) { [nil] }

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


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
63
64
# File 'lib/job_workflow/task.rb', line 36

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



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

def block
  @block
end

#conditionObject (readonly)

: ^(Context) -> bool



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

def condition
  @condition
end

#dependency_waitObject (readonly)

: TaskDependencyWait



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

def dependency_wait
  @dependency_wait
end

#depends_onObject (readonly)

: Array



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

def depends_on
  @depends_on
end

#dry_run_configObject (readonly)

: DryRunConfig



18
19
20
# File 'lib/job_workflow/task.rb', line 18

def dry_run_config
  @dry_run_config
end

#eachObject (readonly)

: ^(Context) -> untyped



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

def each
  @each
end

#enqueueObject (readonly)

: TaskEnqueue



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

def enqueue
  @enqueue
end

#job_nameObject (readonly)

: String



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

def job_name
  @job_name
end

#outputObject (readonly)

: Array



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

def output
  @output
end

#task_retryObject (readonly)

: TaskRetry



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

def task_retry
  @task_retry
end

#throttleObject (readonly)

: TaskThrottle



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

def throttle
  @throttle
end

#timeoutObject (readonly)

: Numeric?



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

def timeout
  @timeout
end

Instance Method Details

#each?Boolean

: () -> bool

Returns:

  • (Boolean)


78
79
80
# File 'lib/job_workflow/task.rb', line 78

def each?
  !each.nil? && !each.equal?(DEFAULT_EACH)
end

#task_nameObject

: () -> Symbol



68
69
70
# File 'lib/job_workflow/task.rb', line 68

def task_name
  name
end

#throttle_prefix_keyObject

: () -> String



73
74
75
# File 'lib/job_workflow/task.rb', line 73

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