Class: Shipit::CommitChecks
Constant Summary
collapse
- OUTPUT_TTL =
10.minutes.to_i
- FINAL_STATUSES =
%w[failed error success].freeze
Instance Method Summary
collapse
#finished?, #run, #success?
Constructor Details
Returns a new instance of CommitChecks.
8
9
10
11
|
# File 'app/models/shipit/commit_checks.rb', line 8
def initialize(commit)
@commit = commit
super(commit)
end
|
Instance Method Details
#initialize_redis_state ⇒ Object
30
31
32
33
|
# File 'app/models/shipit/commit_checks.rb', line 30
def initialize_redis_state
Shipit.redis.set(key('status'), 'scheduled', ex: OUTPUT_TTL)
@status = 'scheduled'
end
|
#output(since: 0) ⇒ Object
44
45
46
|
# File 'app/models/shipit/commit_checks.rb', line 44
def output(since: 0)
Shipit.redis.getrange(key('output'), since, -1)
end
|
#schedule ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'app/models/shipit/commit_checks.rb', line 18
def schedule
return false if Shipit.redis.get(key('status')).present?
synchronize do
return false if Shipit.redis.get(key('status')).present?
initialize_redis_state
end
PerformCommitChecksJob.perform_later(commit:)
true
end
|
#status ⇒ Object
35
36
37
|
# File 'app/models/shipit/commit_checks.rb', line 35
def status
@status ||= Shipit.redis.get(key('status'))
end
|
#status=(status) ⇒ Object
39
40
41
42
|
# File 'app/models/shipit/commit_checks.rb', line 39
def status=(status)
Shipit.redis.set(key('status'), status)
@status = status
end
|
#synchronize(&block) ⇒ Object
13
14
15
16
|
# File 'app/models/shipit/commit_checks.rb', line 13
def synchronize(&block)
@lock ||= Redis::Lock.new(key('lock'), Shipit.redis, expiration: 1, timeout: 2)
@lock.lock(&block)
end
|
#write(output) ⇒ Object
48
49
50
51
52
53
|
# File 'app/models/shipit/commit_checks.rb', line 48
def write(output)
Shipit.redis.pipelined do |pipeline|
pipeline.append(key('output'), output)
pipeline.expire(key('output'), OUTPUT_TTL)
end
end
|