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.
27
28
29
|
# File 'lib/qpush/server/jobs.rb', line 27
def initialize(options)
super
end
|
Instance Method Details
#cron_at ⇒ Object
61
62
63
64
65
|
# File 'lib/qpush/server/jobs.rb', line 61
def cron_at
CronParser.new(@cron).next(Time.now).to_i
rescue => e
raise ServerError, e.message
end
|
#cron_job? ⇒ Boolean
53
54
55
|
# File 'lib/qpush/server/jobs.rb', line 53
def cron_job?
@start_at < Time.now.to_i && !@cron.empty?
end
|
#dead_job? ⇒ Boolean
57
58
59
|
# File 'lib/qpush/server/jobs.rb', line 57
def dead_job?
@total_fail >= @retry_max
end
|
#delay_job? ⇒ Boolean
49
50
51
|
# File 'lib/qpush/server/jobs.rb', line 49
def delay_job?
(@start_at > Time.now.to_i && @cron.empty?) || cron_job?
end
|
#delay_until ⇒ Object
67
68
69
|
# File 'lib/qpush/server/jobs.rb', line 67
def delay_until
@cron.empty? ? @start_at : cron_at
end
|
#mark_failed ⇒ Object
36
37
38
39
|
# File 'lib/qpush/server/jobs.rb', line 36
def mark_failed
@failed = true
@total_fail += 1
end
|
#mark_success ⇒ Object
31
32
33
34
|
# File 'lib/qpush/server/jobs.rb', line 31
def mark_success
@failed = false
@total_success += 1
end
|
45
46
47
|
# File 'lib/qpush/server/jobs.rb', line 45
def perform_job?
@start_at < Time.now.to_i && @cron.empty?
end
|
#retry_at ⇒ Object
71
72
73
|
# File 'lib/qpush/server/jobs.rb', line 71
def retry_at
Time.now.to_i + ((@total_fail**4) + 15 + (rand(30) * (@total_fail + 1)))
end
|
#retry_job? ⇒ Boolean
41
42
43
|
# File 'lib/qpush/server/jobs.rb', line 41
def retry_job?
@retry_max > @total_fail
end
|