lib/resque/scheduler/delaying_extensions.rb in resque-admin-scheduler-1.0.2 vs lib/resque/scheduler/delaying_extensions.rb in resque-admin-scheduler-1.3.0
- old
+ new
@@ -1,11 +1,11 @@
# vim:fileencoding=utf-8
-require 'resque'
+require 'resque_admin'
require_relative 'plugin'
require_relative '../scheduler'
-module Resque
+module ResqueAdmin
module Scheduler
module DelayingExtensions
# This method is nearly identical to +enqueue+ only it also
# takes a timestamp which will be used to schedule the job
# for queueing. Until timestamp is in the past, the job will
@@ -17,25 +17,25 @@
)
end
# Identical to +enqueue_at+, except you can also specify
# a queue in which the job will be placed after the
- # timestamp has passed. It respects Resque.inline option, by
+ # timestamp has passed. It respects ResqueAdmin.inline option, by
# creating the job right away instead of adding to the queue.
def enqueue_at_with_queue(queue, timestamp, klass, *args)
return false unless plugin.run_before_schedule_hooks(klass, *args)
- if Resque.inline? || timestamp.to_i < Time.now.to_i
- # Just create the job and let resque perform it right away with
+ if ResqueAdmin.inline? || timestamp.to_i < Time.now.to_i
+ # Just create the job and let resque_admin perform it right away with
# inline. If the class is a custom job class, call self#scheduled
# on it. This allows you to do things like
- # Resque.enqueue_at(timestamp, CustomJobClass, :opt1 => val1).
- # Otherwise, pass off to Resque.
+ # ResqueAdmin.enqueue_at(timestamp, CustomJobClass, :opt1 => val1).
+ # Otherwise, pass off to ResqueAdmin.
if klass.respond_to?(:scheduled)
klass.scheduled(queue, klass.to_s, *args)
else
- Resque::Job.create(queue, klass, *args)
+ ResqueAdmin::Job.create(queue, klass, *args)
end
else
delayed_push(timestamp, job_to_hash_with_queue(queue, klass, args))
end
@@ -145,11 +145,11 @@
# Given an encoded item, enqueue it now
def enqueue_delayed(klass, *args)
hash = job_to_hash(klass, args)
remove_delayed(klass, *args).times do
- Resque::Scheduler.enqueue_from_config(hash)
+ ResqueAdmin::Scheduler.enqueue_from_config(hash)
end
end
# Given a block, remove jobs that return true from a block
#
@@ -208,11 +208,11 @@
# returns the count of jobs removed.
#
# O(N) where N is the number of jobs scheduled to fire at the given
# timestamp
def remove_delayed_job_from_timestamp(timestamp, klass, *args)
- return 0 if Resque.inline?
+ return 0 if ResqueAdmin.inline?
key = "delayed:#{timestamp.to_i}"
encoded_job = encode(job_to_hash(klass, args))
redis.srem("timestamps:#{encoded_job}", key)
@@ -230,12 +230,12 @@
total_jobs
end
# Discover if a job has been delayed.
# Examples
- # Resque.delayed?(MyJob)
- # Resque.delayed?(MyJob, id: 1)
+ # ResqueAdmin.delayed?(MyJob)
+ # ResqueAdmin.delayed?(MyJob, id: 1)
# Returns true if the job has been delayed
def delayed?(klass, *args)
!scheduled_at(klass, *args).empty?
end
@@ -264,11 +264,11 @@
def job_to_hash_with_queue(queue, klass, args)
{ class: klass.to_s, args: args, queue: queue }
end
def remove_delayed_job(encoded_job)
- return 0 if Resque.inline?
+ return 0 if ResqueAdmin.inline?
timestamps = redis.smembers("timestamps:#{encoded_job}")
replies = redis.pipelined do
timestamps.each do |key|
@@ -315,10 +315,10 @@
relevant_class = (klass.nil? || klass.to_s == job_class)
relevant_class && yield(decoded_payload['args'])
end
def plugin
- Resque::Scheduler::Plugin
+ ResqueAdmin::Scheduler::Plugin
end
end
end
end