Class: SidekiqPublisher::Job
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SidekiqPublisher::Job
- Includes:
- Testing
- Defined in:
- app/models/sidekiq_publisher/job.rb
Constant Summary collapse
- BATCH_KEYS =
%i(id job_id job_class args run_at queue wrapped created_at).freeze
Class Method Summary collapse
- .create_job!(item) ⇒ Object
- .generate_sidekiq_jid ⇒ Object
- .job_retention_period ⇒ Object
- .published!(ids) ⇒ Object
- .purge_expired_published!(instrumenter: Instrumenter.new) ⇒ Object
- .unpublished_batches(batch_size: SidekiqPublisher.batch_size) ⇒ Object
Methods included from Testing
Class Method Details
.create_job!(item) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'app/models/sidekiq_publisher/job.rb', line 23 def self.create_job!(item) create!( job_class: item["class"].to_s, args: item["args"], run_at: item["at"], queue: item["queue"] ) end |
.generate_sidekiq_jid ⇒ Object
32 33 34 |
# File 'app/models/sidekiq_publisher/job.rb', line 32 def self.generate_sidekiq_jid SecureRandom.hex(12) end |
.job_retention_period ⇒ Object
36 37 38 |
# File 'app/models/sidekiq_publisher/job.rb', line 36 def self.job_retention_period SidekiqPublisher.job_retention_period end |
.published!(ids) ⇒ Object
40 41 42 |
# File 'app/models/sidekiq_publisher/job.rb', line 40 def self.published!(ids) where(id: ids).update_all(published_at: Time.now.utc) end |
.purge_expired_published!(instrumenter: Instrumenter.new) ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/models/sidekiq_publisher/job.rb', line 44 def self.purge_expired_published!(instrumenter: Instrumenter.new) SidekiqPublisher.logger.info("#{name} purging expired published jobs.") count = instrumenter.instrument("purge.job") do |notification| notification[:purged_count] = purgeable.delete_all end SidekiqPublisher.logger.info("#{name} purged #{count} expired published jobs.") end |
.unpublished_batches(batch_size: SidekiqPublisher.batch_size) ⇒ Object
52 53 54 55 56 57 |
# File 'app/models/sidekiq_publisher/job.rb', line 52 def self.unpublished_batches(batch_size: SidekiqPublisher.batch_size) unpublished.in_batches(of: batch_size, load: false) do |relation| batch = relation.pluck(*BATCH_KEYS) yield batch.map { |values| Hash[BATCH_KEYS.zip(values)] } end end |