Module: Sidetiq::API

Included in:
Sidetiq
Defined in:
lib/sidetiq/api.rb

Overview

Public: Sidetiq API methods.

Instance Method Summary collapse

Instance Method Details

#retries(worker = nil, &block) ⇒ Object

Public: Recurring jobs currently scheduled for retries.

worker - A Sidekiq::Worker class or String of the class name (optional) block - An optional block that can be given to which each

Sidekiq::SortedEntry instance corresponding to a scheduled job will
be yielded.

Examples

Sidetiq.retries
# => [#<Sidekiq::SortedEntry>, ...]

Sidetiq.retries(MyWorker)
# => [#<Sidekiq::SortedEntry>, ...]

Sidetiq.retries("MyWorker")
# => [#<Sidekiq::SortedEntry>, ...]

Sidetiq.retries do |job|
  # do stuff ...
end
# => [#<Sidekiq::SortedEntry>, ...]

Sidetiq.retries(MyWorker) do |job|
  # do stuff ...
end
# => [#<Sidekiq::SortedEntry>, ...]

Sidetiq.retries("MyWorker") do |job|
  # do stuff ...
end
# => [#<Sidekiq::SortedEntry>, ...]

Yields each Sidekiq::SortedEntry instance. Returns an Array of Sidekiq::SortedEntry objects.


92
93
94
# File 'lib/sidetiq/api.rb', line 92

def retries(worker = nil, &block)
  filter_set(Sidekiq::RetrySet.new, worker, &block)
end

#scheduled(worker = nil, &block) ⇒ Object

Public: Currently scheduled recurring jobs.

worker - A Sidekiq::Worker class or String of the class name (optional) block - An optional block that can be given to which each

Sidekiq::SortedEntry instance corresponding to a scheduled job will
be yielded.

Examples

Sidetiq.scheduled
# => [#<Sidekiq::SortedEntry>, ...]

Sidetiq.scheduled(MyWorker)
# => [#<Sidekiq::SortedEntry>, ...]

Sidetiq.scheduled("MyWorker")
# => [#<Sidekiq::SortedEntry>, ...]

Sidetiq.scheduled do |job|
  # do stuff ...
end
# => [#<Sidekiq::SortedEntry>, ...]

Sidetiq.scheduled(MyWorker) do |job|
  # do stuff ...
end
# => [#<Sidekiq::SortedEntry>, ...]

Sidetiq.scheduled("MyWorker") do |job|
  # do stuff ...
end
# => [#<Sidekiq::SortedEntry>, ...]

Yields each Sidekiq::SortedEntry instance. Returns an Array of Sidekiq::SortedEntry objects.


53
54
55
# File 'lib/sidetiq/api.rb', line 53

def scheduled(worker = nil, &block)
  filter_set(Sidekiq::ScheduledSet.new, worker, &block)
end

#schedulesObject

Public: Returns a Hash of Sidetiq::Schedule instances.


14
15
16
# File 'lib/sidetiq/api.rb', line 14

def schedules
  workers.map(&:schedule)
end

#workersObject

Public: Returns an Array of workers including Sidetiq::Schedulable. Excludes classes which don't define a #perform method.


7
8
9
10
11
# File 'lib/sidetiq/api.rb', line 7

def workers
  Sidetiq::Schedulable.subclasses(true).select do |klass|
    klass.method_defined?(:perform)
  end
end