Class: JobWorkflow::Task

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

Constant Summary collapse

DEFAULT_EACH =

Returns:

  • (Object)
->(_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, 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

Parameters:

  • job_name: (String)
  • name: (Symbol)
  • block: (^(untyped) -> void)
  • condition: (^(Context) -> bool) (defaults to: ->(_ctx) { true })
  • each: (^(Context) -> untyped) (defaults to: nil)
  • enqueue: (true, false, ^(Context) -> bool, Hash[Symbol, untyped]) (defaults to: nil)
  • output: (Hash[Symbol, String]) (defaults to: {})
  • depends_on: (Array[Symbol]) (defaults to: [])
  • task_retry: (Integer, Hash[Symbol, untyped]) (defaults to: 0)
  • throttle: (Integer, Hash[Symbol, untyped]) (defaults to: {})
  • timeout: (Numeric, nil) (defaults to: nil)
  • dependency_wait: (Hash[Symbol, untyped]) (defaults to: {})
  • dry_run: (bool, ^(Context) -> bool) (defaults to: false)


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

#block^(untyped) -> void (readonly)

Signature:

  • ^(untyped) -> void

Returns:

  • (^(untyped) -> void)


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

def block
  @block
end

#condition^(Context) -> bool (readonly)

Signature:

  • ^(Context) -> bool

Returns:



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

def condition
  @condition
end

#dependency_waitTaskDependencyWait (readonly)

Signature:

  • TaskDependencyWait

Returns:



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

def dependency_wait
  @dependency_wait
end

#depends_onArray[Symbol] (readonly)

Signature:

  • Array[Symbol]

Returns:

  • (Array[Symbol])


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

def depends_on
  @depends_on
end

#dry_run_configDryRunConfig (readonly)

Signature:

  • DryRunConfig

Returns:



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

def dry_run_config
  @dry_run_config
end

#each^(Context) -> untyped (readonly)

Signature:

  • ^(Context) -> untyped

Returns:



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

def each
  @each
end

#enqueueTaskEnqueue (readonly)

Signature:

  • TaskEnqueue

Returns:



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

def enqueue
  @enqueue
end

#job_nameString (readonly)

Signature:

  • String

Returns:

  • (String)


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

def job_name
  @job_name
end

#nameSymbol (readonly)

Signature:

  • Symbol

Returns:

  • (Symbol)


84
85
86
# File 'lib/job_workflow/task.rb', line 84

def name
  @name
end

#outputArray[OutputDef] (readonly)

Signature:

  • Array[OutputDef]

Returns:



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

def output
  @output
end

#task_retryTaskRetry (readonly)

Signature:

  • TaskRetry

Returns:



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

def task_retry
  @task_retry
end

#throttleTaskThrottle (readonly)

Signature:

  • TaskThrottle

Returns:



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

def throttle
  @throttle
end

#timeoutNumeric? (readonly)

Signature:

  • Numeric?

Returns:

  • (Numeric, nil)


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_nameSymbol

: () -> Symbol

Returns:

  • (Symbol)


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

def task_name
  name
end

#throttle_prefix_keyString

: () -> String

Returns:

  • (String)


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

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