class Postqueue::Item
An item class.
Postqueue::Item
inserter modules.
This source file provides multiple implementations to insert Postqueue::Items. Which one will be used depends on the “extend XXXInserter” line below.
Public Class Methods
enqueue(op:, entity_id:, ignore_duplicates: false)
click to toggle source
Enqueues an queue item. If the operation is duplicate, and an entry with the same combination of op and entity_id exists already, no new entry will be added to the queue.
Returns the number of items that have been enqueued.
# File lib/postqueue/item/enqueue.rb, line 8 def self.enqueue(op:, entity_id:, ignore_duplicates: false) if entity_id.is_a?(Enumerable) return enqueue_many(op: op, entity_ids: entity_id, ignore_duplicates: ignore_duplicates) end if ignore_duplicates && where(op: op, entity_id: entity_id).present? return 0 end insert_item op: op, entity_id: entity_id 1 end
insert_item(op:, entity_id:)
click to toggle source
# File lib/postqueue/item/inserter.rb, line 11 def self.insert_item(op:, entity_id:) # In contrast to ActiveRecord, which clocks in around 600µs per item, # Simple::SQL's insert only takes 100µs per item. Using prepared # statements would further reduce the runtime to 50µs ::Simple::SQL.insert table_name, op: op, entity_id: entity_id end
postpone(ids)
click to toggle source
# File lib/postqueue/item.rb, line 9 def self.postpone(ids) connection.exec_query <<-SQL UPDATE #{table_name} SET failed_attempts = failed_attempts+1, next_run_at = next_run_at + power(failed_attempts + 1, 1.5) * interval '10 second' WHERE id IN (#{ids.join(',')}) SQL end