Sha256: 255e940f2a6dfbd97759f88667bdfa138d63e5fa55fa2dda4d276b9e5b6eb725

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

# The forward scheduler enqueues a job for every Journey that
# gets sent to the `#schedule`. The job is then stored in the queue
# and gets picked up by the ActiveJob worker normally. This is the simplest
# option if your ActiveJob adapter supports far-ahead scheduling. Some adapters,
# such as SQS, have limitations regarding the maximum delay after which a message
# will become visible. For SQS, the limit is 900 seconds. If the job is further in the future,
# it is likely going to fail to get enqueued. If you are working with a queue adapter
# either:
#
# * Does not allow easy introspection of jobs in the future (like Redis-based queues)
# * Limits the value of the `wait:` parameter
#
# this scheduler is not a good fit for you, and you will need to use the {CyclicScheduler} instead.
class StepperMotor::ForwardScheduler
  def schedule(journey)
    wait = journey.next_step_to_be_performed_at - Time.current
    wait = 0 if wait.negative?
    StepperMotor::PerformStepJob.set(wait: wait).perform_later(journey.to_global_id.to_s)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stepper_motor-0.1.2 lib/stepper_motor/forward_scheduler.rb
stepper_motor-0.1.1 lib/stepper_motor/forward_scheduler.rb
stepper_motor-0.1.0 lib/stepper_motor/forward_scheduler.rb