File: launcher.rb

package info (click to toggle)
ruby-sidekiq-cron 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 408 kB
  • sloc: ruby: 2,156; sh: 8; makefile: 3
file content (49 lines) | stat: -rw-r--r-- 1,266 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'sidekiq/cron/poller'

# For Cron we need to add some methods to Launcher
# so look at the code bellow.
#
# We are creating new cron poller instance and
# adding start and stop commands to launcher.
module Sidekiq
  module Cron
    module Launcher
      DEFAULT_POLL_INTERVAL = 30

      # Add cron poller to launcher.
      attr_reader :cron_poller

      # Add cron poller and execute normal initialize of Sidekiq launcher.
      def initialize(options)
        options[:cron_poll_interval] = DEFAULT_POLL_INTERVAL if options[:cron_poll_interval].nil?

        @cron_poller = Sidekiq::Cron::Poller.new(options) if options[:cron_poll_interval] > 0
        super(options)
      end

      # Execute normal run of launcher and run cron poller.
      def run
        super
        cron_poller.start if @cron_poller
      end

      # Execute normal quiet of launcher and quiet cron poller.
      def quiet
        cron_poller.terminate if @cron_poller
        super
      end

      # Execute normal stop of launcher and stop cron poller.
      def stop
        cron_poller.terminate if @cron_poller
        super
      end
    end
  end
end

Sidekiq.configure_server do
  require 'sidekiq/launcher'

  ::Sidekiq::Launcher.prepend(Sidekiq::Cron::Launcher)
end