Class: QPush::Server::Job
Instance Attribute Summary
Attributes inherited from Base::Job
#args, #created_at, #cron, #failed, #id, #klass, #namespace, #priority, #retry_max, #run_time, #start_at, #total_fail, #total_success
Instance Method Summary
collapse
Methods included from ApiWrapper
#delay, #execute, #morgue, #perform, #queue, #retry, #setup
Methods inherited from Base::Job
#to_json
Constructor Details
#initialize(options) ⇒ Job
Returns a new instance of Job.
19
20
21
|
# File 'lib/qpush/server/jobs.rb', line 19
def initialize(options)
super
end
|
Instance Method Details
#cron_at ⇒ Object
53
54
55
56
57
|
# File 'lib/qpush/server/jobs.rb', line 53
def cron_at
CronParser.new(@cron).next(Time.now).to_i
rescue => e
raise ServerError, e.message
end
|
#cron_job? ⇒ Boolean
45
46
47
|
# File 'lib/qpush/server/jobs.rb', line 45
def cron_job?
@start_at < Time.now.to_i && !@cron.empty?
end
|
#dead_job? ⇒ Boolean
49
50
51
|
# File 'lib/qpush/server/jobs.rb', line 49
def dead_job?
@total_fail >= @retry_max
end
|
#delay_job? ⇒ Boolean
41
42
43
|
# File 'lib/qpush/server/jobs.rb', line 41
def delay_job?
(@start_at > Time.now.to_i && @cron.empty?) || cron_job?
end
|
#delay_until ⇒ Object
59
60
61
|
# File 'lib/qpush/server/jobs.rb', line 59
def delay_until
@cron.empty? ? @start_at : cron_at
end
|
#mark_failed ⇒ Object
28
29
30
31
|
# File 'lib/qpush/server/jobs.rb', line 28
def mark_failed
@failed = true
@total_fail += 1
end
|
#mark_success ⇒ Object
23
24
25
26
|
# File 'lib/qpush/server/jobs.rb', line 23
def mark_success
@failed = false
@total_success += 1
end
|
37
38
39
|
# File 'lib/qpush/server/jobs.rb', line 37
def perform_job?
@start_at < Time.now.to_i && @cron.empty?
end
|
#retry_at ⇒ Object
63
64
65
|
# File 'lib/qpush/server/jobs.rb', line 63
def retry_at
Time.now.to_i + ((@total_fail**4) + 15 + (rand(30) * (@total_fail + 1)))
end
|
#retry_job? ⇒ Boolean
33
34
35
|
# File 'lib/qpush/server/jobs.rb', line 33
def retry_job?
@retry_max > @total_fail
end
|