Class: Tasker::TaskHandler::ClassMethods::StepTemplateDefiner

Inherits:
Object
  • Object
show all
Defined in:
lib/tasker/task_handler/class_methods.rb

Overview

Helper class for defining step templates in task handlers

Defined Under Namespace

Classes: ClassBasedEventRegistrar, YamlEventRegistrar

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ StepTemplateDefiner

Create a new step template definer

Parameters:

  • klass (Class)

    The class where templates are being defined



33
34
35
36
37
38
# File 'lib/tasker/task_handler/class_methods.rb', line 33

def initialize(klass)
  @klass = klass
  @step_templates = []
  @step_handler_class_map = {}
  @step_handler_config_map = {}
end

Instance Attribute Details

#klassClass (readonly)

Returns The class where templates are being defined.

Returns:

  • (Class)

    The class where templates are being defined



21
22
23
# File 'lib/tasker/task_handler/class_methods.rb', line 21

def klass
  @klass
end

#step_handler_class_mapHash<String, String> (readonly)

Returns Mapping of step names to handler class names.

Returns:

  • (Hash<String, String>)

    Mapping of step names to handler class names



24
25
26
# File 'lib/tasker/task_handler/class_methods.rb', line 24

def step_handler_class_map
  @step_handler_class_map
end

#step_handler_config_mapHash<String, Object> (readonly)

Returns Mapping of step names to handler configs.

Returns:

  • (Hash<String, Object>)

    Mapping of step names to handler configs



27
28
29
# File 'lib/tasker/task_handler/class_methods.rb', line 27

def step_handler_config_map
  @step_handler_config_map
end

#step_templatesArray<Tasker::Types::StepTemplate> (readonly)

Returns The defined step templates.

Returns:



18
19
20
# File 'lib/tasker/task_handler/class_methods.rb', line 18

def step_templates
  @step_templates
end

Instance Method Details

#define(**kwargs) ⇒ void

This method returns an undefined value.

Define a new step template

Parameters:

  • kwargs (Hash)

    The step template attributes

Options Hash (**kwargs):

  • :dependent_system (String)

    The system that this step depends on

  • :name (String)

    The name identifier for this step

  • :description (String)

    A description of what this step does

  • :default_retryable (Boolean)

    Whether this step can be retried

  • :default_retry_limit (Integer)

    The maximum number of retry attempts

  • :skippable (Boolean)

    Whether this step can be skipped

  • :handler_class (Class)

    The class that implements the step's logic

  • :depends_on_step (String, nil)

    Name of a step this depends on

  • :depends_on_steps (Array<String>)

    Names of steps this depends on

  • :handler_config (Object, nil)

    Configuration for the step handler

  • :custom_events (Array<Hash>)

    Custom events this step can publish



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/tasker/task_handler/class_methods.rb', line 55

def define(**kwargs)
  dependent_system = kwargs.fetch(:dependent_system, Tasker::Constants::UNKNOWN)
  name = kwargs.fetch(:name)
  handler_class = kwargs.fetch(:handler_class)
  description = kwargs.fetch(:description, name)
  default_retryable = kwargs.fetch(:default_retryable, true)
  default_retry_limit = kwargs.fetch(:default_retry_limit, 3)
  skippable = kwargs.fetch(:skippable, false)
  depends_on_step = kwargs.fetch(:depends_on_step, nil)
  depends_on_steps = kwargs.fetch(:depends_on_steps, [])
  handler_config = kwargs.fetch(:handler_config, nil)
  custom_events = kwargs.fetch(:custom_events, [])

  # Register custom events (both YAML-based and class-based) when step template is defined
  register_custom_events_for_handler(custom_events, handler_class)

  @step_templates << Tasker::Types::StepTemplate.new(
    dependent_system: dependent_system,
    name: name,
    description: description,
    default_retryable: default_retryable,
    default_retry_limit: default_retry_limit,
    skippable: skippable,
    handler_class: handler_class,
    depends_on_step: depends_on_step,
    depends_on_steps: depends_on_steps,
    handler_config: handler_config,
    custom_events: custom_events
  )
end

#register_class_mapvoid

This method returns an undefined value.

Register the mapping of step names to handler classes and configs



89
90
91
92
93
94
# File 'lib/tasker/task_handler/class_methods.rb', line 89

def register_class_map
  @step_templates.each do |template|
    @step_handler_class_map[template.name] = template.handler_class.to_s
    @step_handler_config_map[template.name] = template.handler_config
  end
end