Class: JobWorkflow::Workflow
- Inherits:
-
Object
- Object
- JobWorkflow::Workflow
- Defined in:
- lib/job_workflow/workflow.rb
Instance Attribute Summary collapse
-
#dry_run_config ⇒ Object
: DryRunConfig.
Instance Method Summary collapse
-
#add_argument(argument_def) ⇒ Object
: (ArgumentDef) -> void.
-
#add_hook(type, task_names:, block:) ⇒ Object
: (Symbol, task_names: Array, block: untyped) -> void.
-
#add_schedule(schedule) ⇒ Object
: (Schedule) -> void.
-
#add_task(task) ⇒ Object
: (Task) -> void.
-
#arguments ⇒ Object
: () -> Array.
-
#build_arguments_hash ⇒ Object
: () -> Hash[Symbol, untyped].
-
#build_schedules_hash ⇒ Object
: () -> Hash[Symbol, Hash[Symbol, untyped]].
-
#fetch_task(task_name) ⇒ Object
: (Symbol?) -> Task?.
-
#hooks ⇒ Object
: () -> HookRegistry.
-
#initialize ⇒ Workflow
constructor
: () -> void.
-
#tasks ⇒ Object
: () -> Array.
Constructor Details
#initialize ⇒ Workflow
: () -> void
8 9 10 11 12 13 14 |
# File 'lib/job_workflow/workflow.rb', line 8 def initialize @task_graph = TaskGraph.new @argument_defs = {} #: Hash[Symbol, ArgumentDef] @hook_registry = HookRegistry.new @schedules = {} #: Hash[Symbol, Schedule] @dry_run_config = DryRunConfig.new end |
Instance Attribute Details
#dry_run_config ⇒ Object
: DryRunConfig
5 6 7 |
# File 'lib/job_workflow/workflow.rb', line 5 def dry_run_config @dry_run_config end |
Instance Method Details
#add_argument(argument_def) ⇒ Object
: (ArgumentDef) -> void
27 28 29 |
# File 'lib/job_workflow/workflow.rb', line 27 def add_argument(argument_def) @argument_defs[argument_def.name] = argument_def end |
#add_hook(type, task_names:, block:) ⇒ Object
: (Symbol, task_names: Array, block: untyped) -> void
37 38 39 40 41 42 43 44 |
# File 'lib/job_workflow/workflow.rb', line 37 def add_hook(type, task_names:, block:) return @hook_registry.add_before_hook(task_names:, block:) if type == :before return @hook_registry.add_after_hook(task_names:, block:) if type == :after return @hook_registry.add_around_hook(task_names:, block:) if type == :around return @hook_registry.add_error_hook(task_names:, block:) if type == :error raise ArgumentError, "Invalid hook type: #{type.inspect}" end |
#add_schedule(schedule) ⇒ Object
: (Schedule) -> void
32 33 34 |
# File 'lib/job_workflow/workflow.rb', line 32 def add_schedule(schedule) @schedules[schedule.key] = schedule end |
#add_task(task) ⇒ Object
: (Task) -> void
22 23 24 |
# File 'lib/job_workflow/workflow.rb', line 22 def add_task(task) @task_graph.add(task) end |
#arguments ⇒ Object
: () -> Array
62 63 64 |
# File 'lib/job_workflow/workflow.rb', line 62 def arguments @argument_defs.values end |
#build_arguments_hash ⇒ Object
: () -> Hash[Symbol, untyped]
72 73 74 |
# File 'lib/job_workflow/workflow.rb', line 72 def build_arguments_hash arguments.to_h { |def_obj| [def_obj.name, def_obj.default] } end |
#build_schedules_hash ⇒ Object
: () -> Hash[Symbol, Hash[Symbol, untyped]]
67 68 69 |
# File 'lib/job_workflow/workflow.rb', line 67 def build_schedules_hash @schedules.transform_values(&:to_config) end |
#fetch_task(task_name) ⇒ Object
: (Symbol?) -> Task?
57 58 59 |
# File 'lib/job_workflow/workflow.rb', line 57 def fetch_task(task_name) @task_graph.fetch(task_name) end |
#hooks ⇒ Object
: () -> HookRegistry
47 48 49 |
# File 'lib/job_workflow/workflow.rb', line 47 def hooks @hook_registry end |
#tasks ⇒ Object
: () -> Array
52 53 54 |
# File 'lib/job_workflow/workflow.rb', line 52 def tasks @task_graph.to_a end |