Sha256: 1d158c41796d7412074bff70e9f2d8bf2cc3bea687102520722f47d7abbca2ab

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require 'json'
require 'securerandom'

require_relative '../redis_conn'


module Ryespy
  module Notifier
    class Sidekiq
      
      REDIS_NS_RESQUE = 'resque'
      RESQUE_QUEUE    = 'ryespy'
      
      def initialize(url = nil)
        begin
          @redis_conn = Ryespy::RedisConn.new(url)
        rescue Errno::ECONNREFUSED, Net::FTPError => e
          Ryespy.logger.error { e.to_s }
          
          return
        end
        
        if block_given?
          yield self
          
          close
        end
      end
      
      def close
        @redis_conn.close
      end
      
      def notify(job_class, args)
        @redis_conn.redis.sadd("#{REDIS_NS_RESQUE}:queues", RESQUE_QUEUE)
        
        @redis_conn.redis.rpush("#{REDIS_NS_RESQUE}:queue:#{RESQUE_QUEUE}", {
          # resque
          :class => job_class,
          :args  => args,
          # sidekiq (extra)
          :queue => RESQUE_QUEUE,
          :retry => true,
          :jid   => SecureRandom.hex(12),
        }.to_json)
      end
      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ryespy-0.6.1 lib/ryespy/notifiers/sidekiq.rb
ryespy-0.6.0 lib/ryespy/notifiers/sidekiq.rb