rabbit_jobs 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -75,7 +75,7 @@ module RabbitJobs
75
75
  def mail_errors_to(email = nil, from_email = nil)
76
76
  if email && from_email
77
77
  @data[:mail_errors_to] = email
78
- @data[:mail_errors_form] = from_email
78
+ @data[:mail_errors_from] = from_email
79
79
  else
80
80
  @data[:mail_errors_to]
81
81
  end
@@ -102,7 +102,7 @@ module RabbitJobs
102
102
  raise ArgumentError unless value.is_a?(String) && value != ""
103
103
  @data[:url] = value.to_s
104
104
  else
105
- @data[:url]
105
+ @data[:url] || 'amqp://localhost'
106
106
  end
107
107
  end
108
108
 
@@ -1,9 +1,8 @@
1
1
  # -*- encoding : utf-8 -*-
2
-
3
2
  module RabbitJobs
4
3
  class ErrorMailer
5
4
  def self.enabled?
6
- !!RabbitJobs.config.mail_errors_from && !RabbitJobs.config.mail_errors_from.empty?
5
+ defined?(ActionMailer) && !!RabbitJobs.config.mail_errors_from && !RabbitJobs.config.mail_errors_from.empty?
7
6
  end
8
7
 
9
8
  def self.send(job, error = $!)
@@ -21,7 +21,7 @@ namespace :rj do
21
21
  queues = (ENV['QUEUES'] || ENV['QUEUE']).to_s.split(',')
22
22
  worker = initialize_rj_daemon(RJ::Worker.new(*queues))
23
23
 
24
- worker.work
24
+ exit(0) if worker.work
25
25
  end
26
26
 
27
27
  desc "Start a Rabbit Jobs scheduler"
@@ -1,3 +1,3 @@
1
1
  module RabbitJobs
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -4,7 +4,7 @@ module RabbitJobs
4
4
  class Worker
5
5
  include AmqpHelpers
6
6
 
7
- attr_accessor :pidfile, :background
7
+ attr_accessor :pidfile, :background, :process_name
8
8
 
9
9
  # Workers should be initialized with an array of string queue
10
10
  # names. The order is important: a Worker will check the first
@@ -30,7 +30,9 @@ module RabbitJobs
30
30
 
31
31
  # Subscribes to channel and working on jobs
32
32
  def work(time = 0)
33
- startup
33
+ return false unless startup
34
+
35
+ $0 = self.process_name || "rj_worker (#{queues.join(',')})"
34
36
 
35
37
  processed_count = 0
36
38
  amqp_with_exchange do |connection, exchange|
@@ -39,13 +41,15 @@ module RabbitJobs
39
41
  check_shutdown = Proc.new {
40
42
  if @shutdown
41
43
  RJ.logger.info "Processed jobs: #{processed_count}"
42
- RJ.logger.info "Stopping worker..."
44
+ RJ.logger.info "Stopping worker ##{Process.pid}..."
43
45
 
44
46
  connection.close {
45
- File.delete(self.pidfile) if self.pidfile
47
+ File.delete(self.pidfile) if self.pidfile && File.exists?(self.pidfile)
48
+ RJ.logger.info "##{Process.pid} stopped."
49
+ RJ.logger.close
50
+
46
51
  EM.stop {
47
52
  exit!
48
- RJ.logger.close
49
53
  }
50
54
  }
51
55
  end
@@ -85,6 +89,8 @@ module RabbitJobs
85
89
  check_shutdown.call
86
90
  end
87
91
  end
92
+
93
+ true
88
94
  end
89
95
 
90
96
  def shutdown
@@ -94,7 +100,15 @@ module RabbitJobs
94
100
  def startup
95
101
  # prune_dead_workers
96
102
 
97
- Process.daemon(true) if self.background
103
+ if self.background
104
+ child_pid = fork
105
+ if child_pid
106
+ return false
107
+ else
108
+ # daemonize child process
109
+ Process.daemon(true)
110
+ end
111
+ end
98
112
 
99
113
  if self.pidfile
100
114
  File.open(self.pidfile, 'w') { |f| f << Process.pid }
@@ -108,6 +122,8 @@ module RabbitJobs
108
122
 
109
123
  Signal.trap('TERM') { shutdown }
110
124
  Signal.trap('INT') { shutdown! }
125
+
126
+ true
111
127
  end
112
128
 
113
129
  def shutdown!
@@ -7,8 +7,9 @@ describe RabbitJobs::ErrorMailer do
7
7
  it 'should be enabled when use setup email' do
8
8
  RabbitJobs::ErrorMailer.enabled?.should == false
9
9
  RabbitJobs.configure do |c|
10
- c.mail_errors_to 'dev@exampe.com', 'app@example.com'
10
+ c.mail_errors_to 'dev@example.com', 'app@example.com'
11
11
  end
12
+ puts RJ.config.inspect
12
13
  RabbitJobs::ErrorMailer.enabled?.should == true
13
14
  end
14
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbit_jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-04 00:00:00.000000000 Z
12
+ date: 2012-05-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amqp
16
- requirement: &70239702675840 !ruby/object:Gem::Requirement
16
+ requirement: &70342786851260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.9'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70239702675840
24
+ version_requirements: *70342786851260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bunny
27
- requirement: &70239702675060 !ruby/object:Gem::Requirement
27
+ requirement: &70342786849100 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.7'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70239702675060
35
+ version_requirements: *70342786849100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70239702674400 !ruby/object:Gem::Requirement
38
+ requirement: &70342786847880 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70239702674400
46
+ version_requirements: *70342786847880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rufus-scheduler
49
- requirement: &70239702661400 !ruby/object:Gem::Requirement
49
+ requirement: &70342786843880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '2.0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70239702661400
57
+ version_requirements: *70342786843880
58
58
  description: Background jobs on RabbitMQ
59
59
  email:
60
60
  - lazureykis@gmail.com
@@ -106,12 +106,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  - - ! '>='
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
+ segments:
110
+ - 0
111
+ hash: -2902232038972614332
109
112
  required_rubygems_version: !ruby/object:Gem::Requirement
110
113
  none: false
111
114
  requirements:
112
115
  - - ! '>='
113
116
  - !ruby/object:Gem::Version
114
117
  version: '0'
118
+ segments:
119
+ - 0
120
+ hash: -2902232038972614332
115
121
  requirements: []
116
122
  rubyforge_project:
117
123
  rubygems_version: 1.8.15