Class: Delayed::Backend::Sequel::Job
- Inherits:
-
Object
- Object
- Delayed::Backend::Sequel::Job
- Includes:
- Base
- Defined in:
- lib/delayed/backend/sequel.rb
Overview
A job object that is persisted to the database. Contains the work object as a YAML field.
Class Method Summary collapse
- .before_fork ⇒ Object
-
.clear_locks!(worker_name) ⇒ Object
When a worker is exiting, make sure we don’t have any locked jobs.
- .count(attrs = {}) ⇒ Object
- .create!(attrs) ⇒ Object
-
.db_time_now ⇒ Object
Get the current time (GMT or local depending on DB) Note: This does not ping the DB to get the time, so all your clients must have syncronized clocks.
- .delete_all ⇒ Object
- .reserve(worker, max_run_time = Worker.max_run_time) ⇒ Object
- .silence_log(&block) ⇒ Object
Instance Method Summary collapse
- #before_save ⇒ Object
-
#eql?(obj) ⇒ Boolean
The default behaviour for sequel on #==/#eql? is to check if all values are matching.
- #reload(*args) ⇒ Object
- #save! ⇒ Object
- #update_attributes(attrs) ⇒ Object
Class Method Details
.before_fork ⇒ Object
33 34 35 |
# File 'lib/delayed/backend/sequel.rb', line 33 def self.before_fork ::Sequel::Model.db.disconnect end |
.clear_locks!(worker_name) ⇒ Object
When a worker is exiting, make sure we don’t have any locked jobs.
38 39 40 |
# File 'lib/delayed/backend/sequel.rb', line 38 def self.clear_locks!(worker_name) filter(:locked_by => worker_name).update(:locked_by => nil, :locked_at => nil) end |
.count(attrs = {}) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/delayed/backend/sequel.rb', line 102 def self.count(attrs={}) if attrs.respond_to?(:has_key?) && attrs.has_key?(:conditions) ds = self.where(attrs[:conditions]) if attrs.has_key?(:group) column = attrs[:group] group_and_count(column.to_sym).map do |record| [record[column.to_sym], record[:count]] end else ds.count end else super() end end |
.create!(attrs) ⇒ Object
90 91 92 |
# File 'lib/delayed/backend/sequel.rb', line 90 def self.create!(attrs) new(attrs).save :raise_on_failure => true end |
.db_time_now ⇒ Object
Get the current time (GMT or local depending on DB) Note: This does not ping the DB to get the time, so all your clients must have syncronized clocks.
63 64 65 66 67 68 69 70 71 |
# File 'lib/delayed/backend/sequel.rb', line 63 def self.db_time_now if Time.zone Time.zone.now elsif ::Sequel.database_timezone == :utc Time.now.utc else Time.now end end |
.delete_all ⇒ Object
73 74 75 |
# File 'lib/delayed/backend/sequel.rb', line 73 def self.delete_all dataset.delete end |
.reserve(worker, max_run_time = Worker.max_run_time) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/delayed/backend/sequel.rb', line 42 def self.reserve(worker, max_run_time = Worker.max_run_time) ds = ready_to_run(worker.name, max_run_time) ds = ds.filter("priority >= ?", Worker.min_priority) if Worker.min_priority ds = ds.filter("priority <= ?", Worker.max_priority) if Worker.max_priority ds = ds.filter(:queue => Worker.queues) if Worker.queues.any? ds = ds.by_priority ds = ds.for_update db.transaction do if job = ds.first job.locked_at = self.db_time_now job.locked_by = worker.name job.save(:raise_on_failure => true) job end end end |
.silence_log(&block) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/delayed/backend/sequel.rb', line 94 def self.silence_log(&block) if db.respond_to?(:logger) && db.logger.respond_to?(:silence) db.logger.silence &block else yield end end |
Instance Method Details
#before_save ⇒ Object
11 12 13 14 |
# File 'lib/delayed/backend/sequel.rb', line 11 def before_save super set_default_run_at end |
#eql?(obj) ⇒ Boolean
The default behaviour for sequel on #==/#eql? is to check if all values are matching. This differs from ActiveRecord which checks class and id only. To pass the specs we’re reverting to what AR does here.
122 123 124 |
# File 'lib/delayed/backend/sequel.rb', line 122 def eql?(obj) (obj.class == self.class) && (obj.pk == pk) end |
#reload(*args) ⇒ Object
77 78 79 80 |
# File 'lib/delayed/backend/sequel.rb', line 77 def reload(*args) reset super end |
#save! ⇒ Object
82 83 84 |
# File 'lib/delayed/backend/sequel.rb', line 82 def save! save :raise_on_failure => true end |
#update_attributes(attrs) ⇒ Object
86 87 88 |
# File 'lib/delayed/backend/sequel.rb', line 86 def update_attributes(attrs) update attrs end |