Class: Postqueue::Base
- Inherits:
-
Object
- Object
- Postqueue::Base
- Defined in:
- lib/postqueue/base.rb,
lib/postqueue/base/enqueue.rb,
lib/postqueue/base/processing.rb
Instance Method Summary collapse
- #batch_size(entity_type:, op:) ⇒ Object
- #enqueue(op:, entity_type:, entity_id:) ⇒ Object
- #idempotent?(entity_type:, op:) ⇒ Boolean
-
#process(entity_type: nil, op: nil, batch_size: 100, &block) ⇒ Object
Processes many entries.
- #process_one(entity_type: nil, op: nil, &block) ⇒ Object
Instance Method Details
#batch_size(entity_type:, op:) ⇒ Object
26 27 28 |
# File 'lib/postqueue/base/processing.rb', line 26 def batch_size(entity_type:, op:) 10 end |
#enqueue(op:, entity_type:, entity_id:) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/postqueue/base/enqueue.rb', line 3 def enqueue(op:, entity_type:, entity_id:) # An optimized code path, as laid out below, is 4 times as fast. # However, exec_query changed from Rails 4 to Rails 5. # sql = "INSERT INTO #{item_class.table_name} (op, entity_type, entity_id) VALUES($1, $2, $3)" # binds = [ ] # # binds << ActiveRecord::Attribute.from_user("name", op, ::ActiveRecord::Type::String.new) # binds << ActiveRecord::Attribute.from_user("entity_type", entity_type, ::ActiveRecord::Type::String.new) # binds << ActiveRecord::Attribute.from_user("entity_id", entity_id, ::ActiveRecord::Type::Integer.new) # # Note: Rails 4 does not understand prepare: true # db.exec_query(sql, 'SQL', binds, prepare: true) item_class.create!(op: op, entity_type: entity_type, entity_id: entity_id) end |
#idempotent?(entity_type:, op:) ⇒ Boolean
22 23 24 |
# File 'lib/postqueue/base/processing.rb', line 22 def idempotent?(entity_type:, op:) false end |
#process(entity_type: nil, op: nil, batch_size: 100, &block) ⇒ Object
Processes many entries
process batch_size: 100
9 10 11 12 13 14 15 16 |
# File 'lib/postqueue/base/processing.rb', line 9 def process(entity_type:nil, op:nil, batch_size:100, &block) status, result = item_class.transaction do process_inside_transaction(entity_type: entity_type, op: op, batch_size: batch_size, &block) end raise result if status == :err result end |
#process_one(entity_type: nil, op: nil, &block) ⇒ Object
18 19 20 |
# File 'lib/postqueue/base/processing.rb', line 18 def process_one(entity_type:nil, op:nil, &block) process(entity_type: entity_type, op: op, batch_size: 1, &block) end |