Class: RunTaskJob
Constant Summary
ContainerBrokerBaseJob::JOB_METRIC
Instance Method Summary
collapse
request_id_from_args
request_id_from_args
Instance Method Details
#add_metric(task) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'app/jobs/run_task_job.rb', line 48
def add_metric(task)
Metrics.new("tasks").count(
task_id: task.id,
name: task&.name,
type: task&.execution_type,
slot: task&.slot&.name,
node: task&.slot&.node&.name,
started_at: task.started_at,
duration: task.milliseconds_waiting,
error: task.error,
status: task.status
)
end
|
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
44
45
46
|
# File 'app/jobs/run_task_job.rb', line 8
def perform(task:, slot:)
Rails.logger.debug("Performing RunTaskJob for #{task} #{slot}")
raise "Invalid task status - #{task}" unless task.starting?
raise "Invalid slot status - #{slot}" unless slot.attaching?
runner_id = task.generate_runner_id
task.update!(runner_id: runner_id)
slot.update!(runner_id: runner_id)
slot
.node
.runner_service(:run_task)
.perform(task: task, slot: slot, runner_id: runner_id)
task.mark_as_started!(runner_id: runner_id, slot: slot)
Rails.logger.debug("#{task} marked as started")
slot.mark_as_running(current_task: task, runner_id: runner_id)
Rails.logger.debug("#{slot} marked as running")
add_metric(task)
task
rescue StandardError => e
Rails.logger.debug("Error in RunTaskJob: #{e}")
slot.node.register_error(e.message) if e.is_a?(Node::NodeConnectionError)
slot.release
Rails.logger.debug("#{slot} released")
task.mark_as_retry(error: e.message)
Rails.logger.debug("#{task} marked as retry")
add_metric(task)
Rails.logger.debug("Performed RunTaskJob for #{task} #{slot}")
end
|