Module: SuckerPunch::Job::ClassMethods
- Defined in:
- lib/sucker_punch/job.rb,
lib/sucker_punch/testing/inline.rb
Instance Method Summary collapse
- #__run_perform(*args) ⇒ Object
- #max_jobs(num) ⇒ Object
- #perform_async(*args) ⇒ Object
- #perform_in(_, *args) ⇒ Object
- #workers(num) ⇒ Object
Instance Method Details
#__run_perform(*args) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sucker_punch/job.rb', line 60 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
56 57 58 |
# File 'lib/sucker_punch/job.rb', line 56 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 { __run_perform(*args) } end |
#perform_in(_, *args) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/sucker_punch/job.rb', line 42 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
52 53 54 |
# File 'lib/sucker_punch/job.rb', line 52 def workers(num) self.num_workers = num end |