Sha256: cee83d54270ed4eeca8d23a113d302a694e172d18976f31caffcc03f3666a32c

Contents?: true

Size: 816 Bytes

Versions: 1

Compression:

Stored size: 816 Bytes

Contents

# frozen_string_literal: true

require 'sidekiq/testing'

require 'sidekiq_fake_scheduler/version'
require 'sidekiq_fake_scheduler/job_wrapper'

module SidekiqFakeScheduler
  # Executes all jobs that are due.
  # In contrast to sidekiq's inline mode, this method only executes jobs that
  # were scheduled for now (or any time previous to now).
  # It does not execute jobs that are scheduled for later.
  # This behavior is really powerful in combination with +timecop+.
  # If any executed job enqueues a new job the new job will get executed as well.
  # The execution order is randomized using +Kernel#rand+
  def self.work
    loop do
      performed_one = Sidekiq::Worker.jobs.sort_by { rand }.any? do |job|
        JobWrapper.new(job).try_perform
      end

      break unless performed_one
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-fake-scheduler-0.1.0 lib/sidekiq_fake_scheduler.rb