module Workerholic::Job
Public Class Methods
included(base)
click to toggle source
# File lib/workerholic/job.rb, line 3 def self.included(base) base.extend(ClassMethods) base.job_options end
Public Instance Methods
perform_async(*args)
click to toggle source
# File lib/workerholic/job.rb, line 19 def perform_async(*args) serialized_job, queue_name = prepare_job_for_enqueueing(args) Queue.new(@queue_name || queue_name).enqueue(serialized_job) end
perform_delayed(*args)
click to toggle source
# File lib/workerholic/job.rb, line 25 def perform_delayed(*args) execution_time = Time.now.to_f + verify_delay(args) serialized_job = prepare_job_for_enqueueing(args).first sorted_set = SortedSet.new sorted_set.add(serialized_job, execution_time) end
Private Instance Methods
prepare_job_for_enqueueing(args)
click to toggle source
# File lib/workerholic/job.rb, line 41 def prepare_job_for_enqueueing(args) raise ArgumentError if self.method(:perform).arity != args.size job = JobWrapper.new( klass: @class || self.class, arguments: args, wrapper: self.class, queue: specified_job_options[:queue_name] ) job.statistics.enqueued_at = Time.now.to_f [JobSerializer.serialize(job), specified_job_options[:queue_name]] end
verify_delay(args)
click to toggle source
# File lib/workerholic/job.rb, line 35 def verify_delay(args) raise ArgumentError, 'Delay argument has to be of Numeric type' unless args[0].is_a? Numeric args.shift end