This repository has been archived by the owner on May 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathtask.rb
93 lines (72 loc) · 1.83 KB
/
task.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
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
require 'faraday'
require 'core_ext/hash/compact'
require 'core_ext/hash/deep_symbolize_keys'
require 'active_support/core_ext/string'
require 'active_support/core_ext/class/attribute'
module Travis
class Task
include Logging
extend Instrumentation
class_attribute :run_local
class << self
extend Exceptions::Handling
def run(queue, *args)
Travis::Async.run(self, :perform, async_options(queue), *args)
end
def run_local?
!!run_local || Travis::Features.feature_deactivated?(:travis_tasks)
end
def inline_or_sidekiq
run_local? ? :inline : :sidekiq
end
def async_options(queue)
{ queue: queue, use: inline_or_sidekiq, retries: 8, backtrace: true }
end
def perform(*args)
new(*args).run
end
end
attr_reader :payload, :params
def initialize(payload, params = {})
@payload = payload.deep_symbolize_keys
@params = params.deep_symbolize_keys
end
def run
timeout after: params[:timeout] || 60 do
process
end
end
instrument :run
private
def repository
@repository ||= payload[:repository]
end
def job
@job ||= payload[:job]
end
def build
@build ||= payload[:build]
end
def request
@request ||= payload[:request]
end
def commit
@commit ||= payload[:commit]
end
def pull_request?
build[:pull_request]
end
def http
@http ||= Faraday.new(http_options) do |f|
f.request :url_encoded
f.adapter :net_http
end
end
def http_options
{ ssl: Travis.config.ssl.compact }
end
def timeout(options = { after: 60 }, &block)
Timeout::timeout(options[:after], &block)
end
end
end