Sha256: a7c8e07fcad0cb26f1582ac4ed7c01de4621b972c29cd0e4706757c3b83029ea

Contents?: true

Size: 931 Bytes

Versions: 2

Compression:

Stored size: 931 Bytes

Contents

# Slight modifications from the default Resque tasks
namespace :apn do
  task :setup
  task :work => :sender
  task :workers => :senders

  desc "Start an APN worker"
  task :sender => :setup do
    require 'apn'

    unless defined?(Resque)
      puts "This rake task is only for resque workers"
      return
    end

    APN.password = ENV['CERT_PASS']
    APN.full_certificate_path =  ENV['FULL_CERT_PATH']
    APN.logger = Rails.logger

    worker = ::Resque::Worker.new(APN::Jobs::QUEUE_NAME)

    puts "*** Starting worker to send apple notifications in the background from #{worker}"

    worker.work(ENV['INTERVAL'] || 5) # interval, will block
  end

  desc "Start multiple APN workers. Should only be used in dev mode."
  task :senders do
    threads = []

    ENV['COUNT'].to_i.times do
      threads << Thread.new do
        system "rake apn:work"
      end
    end

    threads.each { |thread| thread.join }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
apn_sender-2.0.1 lib/apn/tasks.rb
apn_sender-2.0.0 lib/apn/tasks.rb