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
- NotSqewerJob =
Class.new(StandardError)
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.
10 11 12 |
# File 'lib/sqewer/submitter.rb', line 10 def self.default new(Sqewer::Connection.default, Sqewer::Serializer.default) end |
Instance Method Details
#submit!(job, **kwargs_for_send) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sqewer/submitter.rb', line 14 def submit!(job, **kwargs_for_send) raise NotSqewerJob.new("Submitted object is not a valid job: #{job.inspect}") unless job.respond_to?(:run) = 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 connection.(, **kwargs_for_send) end |