Class: Marty::CronJob
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- Marty::CronJob
show all
- Defined in:
- app/jobs/marty/cron_job.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#schedule_id ⇒ Object
Returns the value of attribute schedule_id.
2
3
4
|
# File 'app/jobs/marty/cron_job.rb', line 2
def schedule_id
@schedule_id
end
|
Class Method Details
.remove(dj) ⇒ Object
Also known as:
remove_schedule
64
65
66
|
# File 'app/jobs/marty/cron_job.rb', line 64
def remove(dj)
dj.destroy if dj.present?
end
|
.reschedule(schedule_obj:) ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'app/jobs/marty/cron_job.rb', line 55
def reschedule(schedule_obj:)
dj = schedule_obj.delayed_job
return dj.update(cron: schedule_obj.cron) if dj.locked_by?
remove(dj)
set(cron: schedule_obj.cron, schedule_id: schedule_obj.id).
perform_later(*schedule_obj.arguments)
end
|
.schedule(schedule_obj:) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/jobs/marty/cron_job.rb', line 43
def schedule(schedule_obj:)
dj = schedule_obj.delayed_job
return reschedule(schedule_obj: schedule_obj) if dj.present?
cron = schedule_obj.cron
return if cron.blank?
set(cron: cron, schedule_id: schedule_obj.id).perform_later(*schedule_obj.arguments)
end
|
.scheduled?(schedule_id:) ⇒ Boolean
70
71
72
|
# File 'app/jobs/marty/cron_job.rb', line 70
def scheduled?(schedule_id:)
Delayed::Job.find_by(schedule_id: schedule_id).present?
end
|
Instance Method Details
#enqueue(options = {}) ⇒ Object
4
5
6
7
8
|
# File 'app/jobs/marty/cron_job.rb', line 4
def enqueue(options = {})
self.cron = options[:cron] if options[:cron]
self.schedule_id = options[:schedule_id] if options[:schedule_id]
super
end
|
#log_failure(exception, arguments) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/jobs/marty/cron_job.rb', line 20
def log_failure(exception, arguments)
error = {
message: exception.message,
backtrace: exception.backtrace
}
::Marty::BackgroundJob::Log.create!(
job_class: self.class.name,
arguments: arguments,
status: :failure,
error: error
)
end
|
#log_success(arguments) ⇒ Object
34
35
36
37
38
39
40
|
# File 'app/jobs/marty/cron_job.rb', line 34
def log_success(arguments)
::Marty::BackgroundJob::Log.create!(
job_class: self.class.name,
arguments: arguments,
status: :success
)
end
|