-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathset_queue.rb
More file actions
65 lines (54 loc) · 1.66 KB
/
set_queue.rb
File metadata and controls
65 lines (54 loc) · 1.66 KB
1
2
3
4
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true
module Travis
module Scheduler
module Service
class SetQueue < Struct.new(:context, :job, :opts)
include Helper::Logging
include Helper::Context
include Registry
register :service, :set_queue
MSGS = {
redirect: 'Found job.queue: %s. Redirecting to: %s',
queue: 'Setting queue to %s for job=%s',
canceled: 'Build %s has been canceled, job %s being canceled'
}.freeze
def run
info format(MSGS[:queue], queue, job.id)
job.update!(queue:)
end
private
def queue
if job.stage.present? && job.stage.state == "canceled"
info MSGS[:canceled] % [job.source.id, job.id]
payload = { id: job.id, source: 'scheduler' }
Hub.push('job:cancel', payload)
else
@queue ||= redirect(Queue.new(job, config, logger).select)
end
rescue => e
puts "ERROR while trying to queue: #{e.message}"
puts "Backtrace:"
puts e.backtrace.join("\n")@queue ||= redirect(Queue.new(job, config, logger).select)
end
# TODO: confirm we don't need queue redirection any more
def redirect(queue)
redirect = redirections[queue]
info format(MSGS[:redirect], queue, redirect) if redirect
redirect || queue
end
def redirections
config[:queue_redirections] || {}
end
def jid
opts[:jid]
end
def src
opts[:src]
end
def data
super || {}
end
end
end
end
end