Class: Sidekiq::Cron::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/cron/namespace.rb

Class Method Summary collapse

Class Method Details

.allObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sidekiq/cron/namespace.rb', line 4

def self.all
  namespaces = nil

  Sidekiq.redis do |conn|
    namespaces = conn.keys('cron_jobs:*').collect do |key|
      key.split(':').last
    end
  end

  # Adds the default namespace if not present
  has_default = namespaces.detect do |name|
    name == Sidekiq::Cron.configuration.default_namespace
  end

  unless has_default
    namespaces << Sidekiq::Cron.configuration.default_namespace
  end

  namespaces
end

.all_with_countObject



25
26
27
28
29
30
31
32
# File 'lib/sidekiq/cron/namespace.rb', line 25

def self.all_with_count
  all.map do |namespace_name|
    {
      count: count(namespace_name),
      name: namespace_name
    }
  end
end

.count(name = Sidekiq::Cron.configuration.default_namespace) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/sidekiq/cron/namespace.rb', line 34

def self.count(name = Sidekiq::Cron.configuration.default_namespace)
  out = 0
  Sidekiq.redis do |conn|
    out = conn.scard("cron_jobs:#{name}")
  end
  out
end