Module: Sidecloq

Defined in:
lib/sidecloq.rb,
lib/sidecloq/web.rb,
lib/sidecloq/utils.rb,
lib/sidecloq/locker.rb,
lib/sidecloq/runner.rb,
lib/sidecloq/version.rb,
lib/sidecloq/schedule.rb,
lib/sidecloq/scheduler.rb

Defined Under Namespace

Modules: Utils, Web Classes: Locker, Runner, Schedule, Scheduler

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Sidecloq)

    the object that the method was called on



35
36
37
# File 'lib/sidecloq.rb', line 35

def self.configure
  yield self
end

.extract_scheduleObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/sidecloq.rb', line 51

def self.extract_schedule
  # do our best to do this automatically

  # schedule handed to us
  return options[:schedule] if options[:schedule]

  # try for a file
  options[:schedule_file] ||= "config/sidecloq.yml"
  if File.exists?(options[:schedule_file])
    return Schedule.from_yaml(options[:schedule_file])
  elsif defined?(Rails)
    # try rails-root-relative
    full_path = File.join(Rails.root, options[:schedule_file])
    if File.exists?(full_path)
      options[:schedule_file] = full_path
      return Schedule.from_yaml(options[:schedule_file])
    end
  end

  # return an empty schedule
  Schedule.new({})
end

.installObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sidecloq.rb', line 15

def self.install
  Sidekiq.configure_server do |config|
    config.on(:startup) do
      Sidecloq.startup
    end

    config.on(:shutdown) do
      Sidecloq.shutdown
    end
  end
end

.optionsObject



27
28
29
# File 'lib/sidecloq.rb', line 27

def self.options
  @options ||= {}
end

.options=(opts) ⇒ Object



31
32
33
# File 'lib/sidecloq.rb', line 31

def self.options=(opts)
  @options = opts
end

.shutdownObject



47
48
49
# File 'lib/sidecloq.rb', line 47

def self.shutdown
  @runner.stop(options[:timeout] || 10) if @runner
end

.startupObject



39
40
41
42
43
44
45
# File 'lib/sidecloq.rb', line 39

def self.startup
  unless options[:scheduler]
    options[:schedule] ||= extract_schedule
  end
  @runner = Runner.new(options)
  @runner.run
end