Class: Sqewer::Submitter
- Inherits:
-
Struct
- Object
- Struct
- Sqewer::Submitter
- Defined in:
- lib/sqewer/submitter.rb
Overview
A shim for submitting jobs to the queue. Accepts a connection
(something that responds to #send_message
)
and the serializer (something that responds to #serialize
) to
convert the job into the string that will be put in the queue.
Constant Summary collapse
- MAX_PERMITTED_MESSAGE_SIZE_BYTES =
256 * 1024
- NotSqewerJob =
Class.new(Sqewer::Error)
- MessageTooLarge =
Class.new(Sqewer::Error)
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#serializer ⇒ Object
Returns the value of attribute serializer.
Class Method Summary collapse
-
.default ⇒ Object
Returns a default Submitter, configured with the default connection and the default serializer.
Instance Method Summary collapse
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection
5 6 7 |
# File 'lib/sqewer/submitter.rb', line 5 def connection @connection end |
#serializer ⇒ Object
Returns the value of attribute serializer
5 6 7 |
# File 'lib/sqewer/submitter.rb', line 5 def serializer @serializer end |
Class Method Details
.default ⇒ Object
Returns a default Submitter, configured with the default connection and the default serializer.
13 14 15 |
# File 'lib/sqewer/submitter.rb', line 13 def self.default new(Sqewer::Connection.default, Sqewer::Serializer.default) end |
Instance Method Details
#submit!(job, **kwargs_for_send) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sqewer/submitter.rb', line 17 def submit!(job, **kwargs_for_send) validate_job_responds_to_run!(job) = if delay_by_seconds = kwargs_for_send[:delay_seconds] clamped_delay = clamp_delay(delay_by_seconds) kwargs_for_send[:delay_seconds] = clamped_delay # Pass the actual delay value to the serializer, to be stored in executed_at serializer.serialize(job, Time.now.to_i + delay_by_seconds) else serializer.serialize(job) end (, job) connection.(, **kwargs_for_send) end |