Sha256: 15012bc4c16f3fd2f8aac2238ff445bb84d377d85cd6c1d7350eb310eb438a1c

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

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(config, **kwargs)
        config[:cron_poll_interval] = DEFAULT_POLL_INTERVAL if config[:cron_poll_interval].nil?

        @cron_poller = Sidekiq::Cron::Poller.new(config) if config[:cron_poll_interval] > 0
        super
      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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sidekiq-cron-1.12.0 lib/sidekiq/cron/launcher.rb
sidekiq-cron-1.11.0 lib/sidekiq/cron/launcher.rb
sidekiq-cron-1.10.1 lib/sidekiq/cron/launcher.rb
sidekiq-cron-1.10.0 lib/sidekiq/cron/launcher.rb