Class: Qyu::Concerns::WorkflowDescriptorValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/qyu/models/concerns/workflow_descriptor_validator.rb

Overview

Qyu::Concerns::WorkflowDescriptorValidator

Constant Summary collapse

ALLOWED_KEYS =

TODO: starts_parallel is a the same as starts_manually. The latter will be removed in Qyu v2

%w(queue waits_for starts starts_parallel starts_manually starts_with_params).freeze
DEPRECATED_KEYS =
%(starts_manually)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(descriptor) ⇒ WorkflowDescriptorValidator


13
14
15
16
# File 'lib/qyu/models/concerns/workflow_descriptor_validator.rb', line 13

def initialize(descriptor)
  @descriptor = descriptor
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors


11
12
13
# File 'lib/qyu/models/concerns/workflow_descriptor_validator.rb', line 11

def errors
  @errors
end

Instance Method Details

#valid?Boolean

validates a workflow's descriptor


21
22
23
24
# File 'lib/qyu/models/concerns/workflow_descriptor_validator.rb', line 21

def valid?
  validate
  @errors.empty?
end

#validateObject


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/qyu/models/concerns/workflow_descriptor_validator.rb', line 26

def validate
  @errors << 'Descriptor type must be a Hash.' unless validate_descriptor_type
  @errors << 'Entry points (starts) must be an Array.' unless validate_entry_points_type
  @errors << 'Tasks must be a Hash.' unless validate_tasks_type
  unless validate_entry_points_presence
    @errors << 'There must be at least 1 entry point, and all entry points must exist in the tasks Hash.'
  end
  @errors << 'There must be at least 1 task in the tasks Hash.' unless validate_tasks_presence

  tasks.keys.each do |task_name|
    unless validate_queue_presence(task_name)
      @errors << "#{task_name} must have a valid queue"
    end
    unless validate_task_keys(task_name)
      @errors << "#{task_name} must only contain the following keys: #{ALLOWED_KEYS}"
    end
    unless validate_task_reference_formats(task_name)
      @errors << "#{task_name} must follow the reference declaration format"
    end
    unless validate_referenced_tasks(task_name)
      @errors << "#{task_name} must list existing tasks in its references"
    end
    unless validate_sync_condition_params(task_name)
      @errors << "#{task_name} must pass the correct parameters to the sync task"
    end
  end
rescue => ex
  Qyu.logger.error "Error while validation: #{ex.class}: #{ex.message}"
  Qyu.logger.error "Backtrace: #{ex.backtrace.join("\n")}"
  @errors << "#{ex.class}: #{ex.message}"
end