Module: SuckerPunch::Job::ClassMethods

Defined in:
lib/sucker_punch/job.rb,
lib/sucker_punch/testing/inline.rb

Instance Method Summary collapse

Instance Method Details

#__run_perform(*args) ⇒ Object


58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sucker_punch/job.rb', line 58

def __run_perform(*args)
  SuckerPunch::Counter::Busy.new(self.to_s).increment
  result = self.new.perform(*args)
  SuckerPunch::Counter::Processed.new(self.to_s).increment
  result
rescue => ex
  SuckerPunch::Counter::Failed.new(self.to_s).increment
  SuckerPunch.exception_handler.call(ex, self, args)
ensure
  SuckerPunch::Counter::Busy.new(self.to_s).decrement
end

#max_jobs(num) ⇒ Object


54
55
56
# File 'lib/sucker_punch/job.rb', line 54

def max_jobs(num)
  self.num_jobs_max = num
end

#perform_async(*args) ⇒ Object


35
36
37
38
39
# File 'lib/sucker_punch/job.rb', line 35

def perform_async(*args)
  return unless SuckerPunch::RUNNING.true?
  queue = SuckerPunch::Queue.find_or_create(self.to_s, num_workers, num_jobs_max)
  queue.post(args) { |job_args| __run_perform(*job_args) }
end

#perform_in(_, *args) ⇒ Object


41
42
43
44
45
46
47
48
# File 'lib/sucker_punch/job.rb', line 41

def perform_in(interval, *args)
  return unless SuckerPunch::RUNNING.true?
  queue = SuckerPunch::Queue.find_or_create(self.to_s, num_workers, num_jobs_max)
  job = Concurrent::ScheduledTask.execute(interval.to_f, args: args, executor: queue) do
    __run_perform(*args)
  end
  job.pending?
end

#workers(num) ⇒ Object


50
51
52
# File 'lib/sucker_punch/job.rb', line 50

def workers(num)
  self.num_workers = num
end