-
Notifications
You must be signed in to change notification settings - Fork 1
/
clock.rb
25 lines (21 loc) · 939 Bytes
/
clock.rb
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
require "clockwork"
require_relative "job_cancel"
USERNAME = ENV["CIRCLECI_USERNAME"]
PROJECTS = (ENV["CIRCLECI_PROJECTS"] || ENV["CIRCLECI_PROJECT"]).split
API_TOKEN = ENV["CIRCLECI_API_TOKEN"]
LOG = Logger.new(STDOUT)
LOG.level = Logger::INFO
module Clockwork
configure do |config|
config[:logger] = LOG
end
PROJECTS.each do |project|
every(20.seconds, "cancel superfluous builds for project: #{project}") do
api_token = ENV["CIRCLECI_API_TOKEN_#{project}"] || API_TOKEN
branches_to_ignore = (ENV["BRANCHES_TO_IGNORE_#{project}"] || "").split
branches_that_deploy = (ENV["BRANCHES_THAT_DEPLOY_#{project}"] || "").split
branches_with_safe_time = Hash[(ENV["BRANCHES_WITH_SAFE_TIME_#{project}"] || "").split.map { |branch_config| branch_config.split(",") }]
JobCancel.perform(api_token, USERNAME, project, branches_to_ignore, branches_that_deploy, branches_with_safe_time)
end
end
end