Sha256: d638e9b968a574f23be27ef8409f9c3cf303e10211fc845cac2eb9f6c2d60ee2

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require "sidekiq"
require_relative "job_signal/version"
require_relative "job_signal/server_middleware"
require_relative "job_signal/receiver"
require_relative "job_signal/web"

module Sidekiq
  module JobSignal
    class << self
      def handlers
        @handlers ||= []
      end

      def on_quit(&block)
        handlers << block
      end

      def quit(job_class: "", jid: "")
        ::Sidekiq.redis do |r|
          r.pipelined do |pipeline|
            pipeline.set "jobsignal-#{jid}", "quit", ex: 86_400 if jid && !jid.empty?
            pipeline.set "jobsignal-#{job_class}", "quit", ex: 86_400 if job_class && !job_class.empty?
          end
        end
      end

      def delete_signal(job_class: "", jid: "")
        ::Sidekiq.redis do |r|
          r.pipelined do |pipeline|
            pipeline.del("jobsignal-#{jid}") if jid && !jid.empty?
            pipeline.del("jobsignal-#{job_class}") if job_class && !job_class.empty?
          end
        end
      end

      def quitting?(job_class: "", jid: "")
        results = ::Sidekiq.redis do |r|
          r.pipelined do |pipeline|
            pipeline.get("jobsignal-#{jid}") if jid && !jid.empty?
            pipeline.get("jobsignal-#{job_class}") if job_class && !job_class.empty?
          end
        end
        results.include?("quit")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-job-signal-0.1.2 lib/sidekiq/job_signal.rb