Class: Kuroko2::Workflow::Task::SubProcess
- Inherits:
-
Base
- Object
- Base
- Kuroko2::Workflow::Task::SubProcess
show all
- Defined in:
- lib/autoload/kuroko2/workflow/task/sub_process.rb
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#execute ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/autoload/kuroko2/workflow/task/sub_process.rb', line 5
def execute
validate
if (sub_process_id = token.context['sub_process_id'])
instance = JobInstance.find(sub_process_id)
if instance.working?
:pass
elsif instance.canceled_at?
message = "(token #{token.uuid}) Sub process '##{instance.job_definition.id} #{instance.job_definition.name}' instance##{instance.job_definition.id}/#{instance.id} is canceled."
token.job_instance.logs.warn(message)
Kuroko2.logger.info(message)
token.mark_as_failure
:failure
else
token.context['sub_process_id'] = nil
message = "(token #{token.uuid}) Sub process '##{instance.job_definition.id} #{instance.job_definition.name}' instance##{instance.job_definition.id}/#{instance.id} is finished."
token.job_instance.logs.info(message)
Kuroko2.logger.info(message)
:next
end
else
definition = JobDefinition.find(@node.option)
instance = definition.job_instances.create
instance.logs.info("Launched by '##{token.job_definition.id} #{token.job_definition.name}' instance##{token.job_definition.id}/#{token.job_instance.id}.")
token.job_instance.logs.info("(token #{token.uuid}) Launched '##{instance.job_definition.id} #{instance.job_definition.name}' instance##{instance.job_definition.id}/#{instance.id} as a sub process.")
token.context['sub_process_id'] = instance.id
:pass
end
rescue ActiveRecord::RecordNotFound
raise Workflow::AssertionError, "Job definition is not found for #{option}"
end
|
#validate ⇒ Object
45
46
47
48
49
|
# File 'lib/autoload/kuroko2/workflow/task/sub_process.rb', line 45
def validate
unless /\A\d+\z/ === option
raise Workflow::AssertionError, "Option of sub process should be a number."
end
end
|