rock-queue 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -3,11 +3,11 @@ require 'rake/gempackagetask'
3
3
  require 'rubygems/specification'
4
4
  require 'spec/rake/spectask'
5
5
  require 'date'
6
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'
6
+ $LOAD_PATH.unshift 'lib'
7
7
  require 'rock-queue/tasks'
8
8
 
9
9
  GEM = "rock-queue"
10
- GEM_VERSION = "0.1.7"
10
+ GEM_VERSION = "0.1.8"
11
11
  AUTHOR = "Grzegorz Kazulak"
12
12
  EMAIL = "gregorz.kazulak@gmail.com"
13
13
  HOMEPAGE = "http://github.com/grzegorzkazulak/rock-queue"
@@ -34,6 +34,8 @@ Rake::GemPackageTask.new(spec) do |pkg|
34
34
  pkg.gem_spec = spec
35
35
  end
36
36
 
37
+ task :default => :test
38
+
37
39
  desc "install the gem locally"
38
40
  task :install => [:package] do
39
41
  sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
@@ -46,14 +48,12 @@ task :make_spec do
46
48
  end
47
49
  end
48
50
 
49
- desc "Run all examples (or a specific spec with TASK=spec/some_file.rb)"
50
- Spec::Rake::SpecTask.new('spec') do |t|
51
- t.spec_opts = ["-cfs"]
52
- t.spec_files = begin
53
- if ENV["TASK"]
54
- ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
55
- else
56
- FileList['spec/**/*_spec.rb']
57
- end
51
+ desc "Run tests"
52
+ task :test do
53
+ # Don't use the rake/testtask because it loads a new
54
+ # Ruby interpreter - we want to run tests with the current
55
+ # `rake` so our library manager still works
56
+ Dir['test/*_test.rb'].each do |f|
57
+ require f
58
58
  end
59
59
  end
@@ -1,7 +1,7 @@
1
1
  begin
2
2
  require "beanstalk-client"
3
3
  rescue
4
- puts "You need `beanstalk-client` gem to use the Beanstalkd rock-queue interface"
4
+ RockQueue::Base.logger.error "You need `beanstalk-client` gem to use the Beanstalkd rock-queue interface"
5
5
  exit
6
6
  end
7
7
 
@@ -1,7 +1,7 @@
1
1
  begin
2
2
  require "delayed_job"
3
3
  rescue
4
- puts "You need `delayed_job` gem to use the Delayed Job rock-queue interface"
4
+ RockQueue::Base.logger.error "You need `delayed_job` gem to use the Delayed Job rock-queue interface"
5
5
  exit
6
6
  end
7
7
 
@@ -1,7 +1,7 @@
1
1
  begin
2
2
  require 'resque'
3
3
  rescue
4
- puts "You need `resque` gem to use the Resque rock-queue interface"
4
+ RockQueue::Base.logger.error "You need `resque` gem to use the Resque rock-queue interface"
5
5
  exit
6
6
  end
7
7
 
@@ -1,7 +1,7 @@
1
1
  module RockQueue
2
2
  class Config
3
3
 
4
- attr_accessor :adapter, :host, :port
4
+ attr_accessor :adapter, :host, :port, :log
5
5
 
6
6
  # Return the instance
7
7
  def self.instance
@@ -12,10 +12,10 @@ module RockQueue
12
12
  begin
13
13
  require 'mail'
14
14
  rescue
15
- puts "You need `mail` gem to use the Email Notifier"
15
+ RockQueue::Base.logger.error "You need `mail` gem to use the Email Notifier"
16
16
  end
17
17
 
18
- puts "Sending e-mail message: #{error.message}"
18
+ RockQueue::Base.logger.info "Sending e-mail message: #{error.message}"
19
19
 
20
20
  Mail.defaults do
21
21
  smtp do
@@ -11,15 +11,14 @@ namespace :rock_queue do
11
11
  task :work do
12
12
  worker = RockQueue::Worker.new
13
13
  worker.verbose = ENV['VERBOSE']
14
- puts "=> Rock-queue worker initialized (#{worker})"
15
-
14
+ RockQueue::Base.logger.info "=> Rock-queue worker initialized (#{worker})"
16
15
  pid = fork do
17
16
  File.open(file_path, "wb") { |f| f.write(Process.pid) }
18
17
  worker.work
19
18
  end
20
19
  end
21
20
 
22
-
21
+ desc "Stop a Rock Queue worker"
23
22
  task :stop do
24
23
  fork do
25
24
  if File.exists?(file_path)
@@ -34,4 +33,4 @@ namespace :rock_queue do
34
33
  end
35
34
  end
36
35
  end
37
- end
36
+ end
@@ -5,35 +5,38 @@ module RockQueue
5
5
 
6
6
  # Initialize connection to queue server
7
7
  def initialize
8
- puts "=> Initializing..."
9
8
  config = RockQueue::Config.settings
10
9
  @queue = RockQueue::Base.new config.adapter, {
11
10
  :server => config.host,
12
- :port => config.port
11
+ :port => config.port,
12
+ :log => config.log
13
13
  }
14
+ RockQueue::Base.logger.info "=> Initializing..."
14
15
  end
15
16
 
16
17
  # Main worker loop where all jobs are beeing pulled of the queue.
17
18
  # This is also a place where every job starts and ends it's lifecycle.
18
19
  def work
19
- puts "=> Worker ready. Hold your horses!"
20
+ RockQueue::Base.logger.info "=> Worker ready. Hold your horses!"
20
21
  loop do
21
- begin
22
- @queue.receive do |queue|
23
- if queue
22
+ ActiveRecord::Base.verify_active_connections!
23
+ @queue.receive do |queue|
24
+ if queue
25
+ begin
24
26
  # code that actually performs the action
25
27
  args = queue.args.first
26
- puts "=> Processing class #{queue.object.name} with params: #{args.inspect}"
28
+ RockQueue::Base.logger.info "=> Processing class #{queue.object.name} with params: #{args.inspect}"
27
29
  args.empty? ? queue.object.perform : queue.object.perform(args)
30
+ rescue Object => e
31
+ # Add failed processing and retry
32
+ if queue.add_fail(e)
33
+ sleep(queue.get_sleep_time)
34
+ RockQueue::Base.logger.error "=> Processing fail! Retrying #{queue.fails.length}"
35
+ RockQueue::Base.logger.error " Message: #{e.message}"
36
+ retry
37
+ end
28
38
  end
29
39
  end
30
- rescue Object => e
31
- # Add failed processing and retry
32
- if queue.add_fail(e)
33
- sleep(queue.get_sleep_time)
34
- puts "=> Processing fail! Retrying #{queue.fails.length}"
35
- retry
36
- end
37
40
  end
38
41
  end
39
42
  end
data/lib/rock-queue.rb CHANGED
@@ -23,26 +23,30 @@ module RockQueue
23
23
  autoload :ActiveRecordHelper, 'rock-queue/active_record_helper'
24
24
 
25
25
  attr_reader :adapter
26
-
26
+
27
+
27
28
  class Base
28
-
29
+
29
30
  # Initializes the whole thing and makes the connection to the
30
31
  # queueing server using selected adapter (passed as lowercased symbol)
31
32
  def initialize(adapter, *options)
32
33
  # Any better way to do this? :-)
33
34
  options = options.first
34
35
  if options.include?(:server) && options.include?(:port)
35
- case adapter
36
- when :beanstalkd
37
- @adapter = Beanstalkd.new(options)
38
- when :resque
39
- @adapter = ResqueQueue.new(options)
40
- when :delayed_job
41
- @adapter = DelayedJob.new(options)
42
- end
36
+ case adapter
37
+ when :beanstalkd
38
+ @adapter = Beanstalkd.new(options)
39
+ when :resque
40
+ @adapter = ResqueQueue.new(options)
41
+ when :delayed_job
42
+ @adapter = DelayedJob.new(options)
43
+ end
43
44
  else
44
45
  raise ArgumentError
45
46
  end
47
+
48
+ # Initialize logger
49
+ @@logger = Logger.new(options[:log].nil? ? STDOUT : options[:log])
46
50
  end
47
51
 
48
52
 
@@ -60,18 +64,22 @@ module RockQueue
60
64
  def receive
61
65
  if block_given?
62
66
  obj, args = @adapter.pop
63
- if obj
64
- yield QueueObject.new(obj, args)
65
- end
67
+ yield QueueObject.new(obj, args) if obj
66
68
  else
67
69
  raise 'No block given'
68
70
  end
69
71
  end
70
72
 
71
-
73
+ # Calling adapter method
72
74
  def method_missing(sym, *args, &block)
73
- @adapter.send sym, *args, &block
75
+ @adapter.send sym, *args, &block
76
+ end
77
+
78
+ # Returns Rock Queue logger
79
+ def self.logger
80
+ @@logger
74
81
  end
75
82
 
76
83
  end
84
+
77
85
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 7
9
- version: 0.1.7
8
+ - 8
9
+ version: 0.1.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Grzegorz Kazulak
@@ -14,7 +14,7 @@ autorequire: rock-queue
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-02-21 00:00:00 +01:00
17
+ date: 2010-02-22 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20