Sha256: def2059ee056175d29d3713ec7f786514a04ec7f4ba14e176ecaf758005afa4c

Contents?: true

Size: 557 Bytes

Versions: 1

Compression:

Stored size: 557 Bytes

Contents

# frozen_string_literal: true

module SidekiqFakeScheduler
  class JobWrapper
    def initialize(job)
      @job = job
    end

    def try_perform
      return false if @job.key?('at') && @job['at'] > Time.now.to_f

      perform
      true
    end

    def perform
      delete_from_queues
      worker_class.new.perform(*@job['args'])
    end

    private

    def worker_class
      Object.const_get @job['class']
    end

    def delete_from_queues
      Sidekiq::Queues[@job['queue']].delete @job
      worker_class.jobs.delete @job
    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/job_wrapper.rb