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
44
45
46
47
48
49
50
51
52
53
54
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
85
86
87
88
89
90
91
92
93
|
# File 'app/jobs/solidflow/jobs/run_task_job.rb', line 10
def perform(execution_id, step_name, task_name, arguments, )
= .deep_symbolize_keys
arguments = arguments.deep_symbolize_keys if arguments.respond_to?(:deep_symbolize_keys)
task_class = SolidFlow.task_registry.fetch(task_name)
workflow_class = SolidFlow.configuration.workflow_registry.fetch(.fetch(:workflow_name))
attempt = [:attempt] || 1
idempotency_key = [:idempotency_key]
compensation = [:compensation]
result = task_class.execute(arguments: arguments || {}, headers:)
SolidFlow.store.with_execution(execution_id) do |_|
if compensation
SolidFlow.store.record_compensation_result(
execution_id:,
step: step_name.to_sym,
compensation_task: [:compensation_task],
result:
)
else
SolidFlow.store.record_task_result(
execution_id:,
workflow_class:,
step: step_name.to_sym,
result:,
attempt:,
idempotency_key: idempotency_key
)
end
end
SolidFlow.instrument(
"solidflow.task.completed",
execution_id:,
workflow: workflow_class.workflow_name,
step: step_name,
task: task_name,
attempt:,
result:,
compensation: compensation
)
rescue Errors::TaskFailure => failure
retryable = retryable?(workflow_class, step_name, attempt, )
SolidFlow.store.with_execution(execution_id) do |_|
if [:compensation]
SolidFlow.store.record_compensation_failure(
execution_id:,
step: step_name.to_sym,
compensation_task: [:compensation_task],
error: {
message: failure.message,
class: failure.details&.fetch(:class, failure.class.name),
backtrace: Array(failure.details&.fetch(:backtrace, failure.backtrace))
}
)
else
SolidFlow.store.record_task_failure(
execution_id:,
workflow_class:,
step: step_name.to_sym,
attempt:,
error: {
message: failure.message,
class: failure.details&.fetch(:class, failure.class.name),
backtrace: Array(failure.details&.fetch(:backtrace, failure.backtrace))
},
retryable:
)
end
end
SolidFlow.instrument(
"solidflow.task.failed",
execution_id:,
workflow: workflow_class.workflow_name,
step: step_name,
task: task_name,
attempt:,
error: failure,
compensation: [:compensation]
)
end
|