rabbit_jobs 0.5.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -201,10 +201,6 @@ module RabbitJobs
201
201
  yaml['queues'].each do |name, params|
202
202
  queue name, symbolize_keys!(params) || {}
203
203
  end
204
-
205
- yaml['workers'].each do |name, params|
206
- worker name, symbolize_keys!(params) || {}
207
- end
208
204
  end
209
205
  end
210
206
 
@@ -1,6 +1,3 @@
1
- # require 'rabbit_jobs/tasks'
2
- # will give you the resque tasks
3
-
4
1
  require 'rabbit_jobs'
5
2
  require 'logger'
6
3
  require 'rake'
@@ -22,202 +19,23 @@ end
22
19
 
23
20
  namespace :rj do
24
21
  task :environment do
25
- # Rails.application.eager_load!
26
22
  Rails.application.require_environment!
27
23
  end
28
24
 
29
- # MULTIPROCESS
30
- namespace :worker do
31
- desc "Start a Rabbit Jobs workers from config/rj_workers.yml"
32
- task :start => [:environment, :load_config] do
33
- make_dirs
34
- RJ.config.workers.each do |worker_name, worker_props|
35
- (1..worker_props[:instances].to_i).each do |worker_num|
36
- unless @do_only.count > 0 && !@do_only.include?("#{worker_name}-#{worker_num}")
37
- queues = (worker_props[:queue] || worker_props[:queues] || "").split(' ')
38
-
39
- worker = RJ::Worker.new(*queues)
40
- worker.background = true
41
- worker.process_name = "rj_worker #{worker_name}##{worker_num} #{rails_env} [#{queues.join(',')}]"
42
- worker.pidfile = app_root.join("tmp/pids/rj_worker_#{rails_env}_#{worker_name}_#{worker_num}.pid")
43
- RJ.logger = ::Logger.new(app_root.join("log/rj_worker_#{rails_env}_#{worker_name}_#{worker_num}.log"), 'daily')
44
- RJ.logger.formatter = nil
45
- RJ.logger.progname = 'rj_worker'
46
- RJ.logger.level = Logger::INFO if ENV['VERBOSE']
47
- puts "Starting #{worker_name}##{worker_num}"
48
-
49
- # завершаем копию процесса, если воркер уже отработал
50
- exit! if worker.work
51
- end
52
- end
53
- end
54
- end
55
-
56
- task :stop => :load_config do
57
- # получаем идентификаторы процессов
58
- pids = {}
59
- errors = []
60
-
61
- RJ.config.workers.each do |worker_name, worker_props|
62
- worker_num = 1
63
- worker_props[:instances].to_i.times do
64
- unless (@do_only.count > 0) && !@do_only.include?("#{worker_name}-#{worker_num}")
65
- pidfile = app_root.join("tmp/pids/rj_worker_#{rails_env}_#{worker_name}_#{worker_num}.pid")
66
-
67
- unless File.exists?(pidfile)
68
- msg = "Pidfile not found: #{pidfile}"
69
- errors << msg
70
- $stderr.puts msg
71
- else
72
- pid = open(pidfile).read.to_i
73
- pids[pid] = pidfile
74
- queues = (worker_props[:queue] || worker_props[:queues] || "").split(' ')
75
- puts "Stopping rj_worker #{worker_name}##{worker_num} #{rails_env} [#{queues.join(',')}]"
76
- end
77
- end
78
- worker_num += 1
79
- end
80
- end
81
-
82
- # пытаемся их убить
83
- killed_pids = []
84
- pids.each do |pid, pidfile|
85
- begin
86
- puts "try killing ##{pid}"
87
- Process.kill("TERM", pid)
88
- rescue => e
89
- errors << "Not found process: #{pid} from #{pidfile}"
90
- $stderr.puts errors.last
91
- $stderr.puts "Removing pidfile ..."
92
- File.delete(pidfile) if File.exist?(pidfile)
93
- end
94
- end
95
-
96
- while killed_pids.count != pids.keys.count
97
- pids.each_key do |pid|
98
- begin
99
- Process.kill(0, pid)
100
- stopped = false
101
- break
102
- rescue
103
- killed_pids.push(pid) unless killed_pids.include?(pid)
104
- end
105
- end
106
- print '.'
107
- sleep 1
108
- end
109
-
110
- fail(errors.join("\r\n")) if not errors.empty?
111
-
112
- puts "\nrj_worker stopped."
113
- end
114
-
115
- task :status => :load_config do
116
- errors = []
117
-
118
- RJ.config.workers.each do |worker_name, worker_props|
119
- worker_num = 1
120
- worker_props[:instances].to_i.times do
121
- pidfile = app_root.join("tmp/pids/rj_worker_#{rails_env}_#{worker_name}_#{worker_num}.pid")
122
-
123
- unless File.exists?(pidfile)
124
- errors << "Pidfile not found: #{pidfile}"
125
- else
126
- pid = open(pidfile).read.to_i
127
- begin
128
- raise "must return 1" unless Process.kill(0, pid) == 1
129
- rescue
130
- errors << "Pidfile found but process not respond: #{pidfile}\r\nRemoving pidfile."
131
- File.delete(pidfile) if File.exist?(pidfile)
132
- end
133
- end
134
- worker_num += 1
135
- end
136
- end
137
-
138
- if errors.empty?
139
- puts "ok"
140
- else
141
- fail errors.join("\r\n")
142
- end
143
- end
144
-
145
- task :load_config do
146
- @do_only = ENV["WORKERS"] ? ENV["WORKERS"].strip.split : []
147
- @do_only.each do |worker|
148
- worker_name, worker_num = worker.split('-')
149
- unless RJ.config.workers.keys.include?(worker_name) && RJ.config.workers[worker_name][:instances].to_i >= worker_num.to_i
150
- raise "Worker #{worker} not found."
151
- end
152
- end
153
- end
25
+ desc "Start a Rabbit Jobs worker"
26
+ task :worker => :environment do
27
+ queues = (ENV['QUEUES'] || ENV['QUEUES'] || "").split(',')
28
+ make_dirs
29
+ worker = RJ::Worker.new(*queues)
30
+ worker.process_name = "rj_worker #{rails_env} [#{queues.join(',')}]"
31
+ exit(worker.work)
154
32
  end
155
33
 
156
- namespace :scheduler do
157
- task :start do
158
- make_dirs
159
-
160
- scheduler = RabbitJobs::Scheduler.new
161
-
162
- scheduler.background = true
163
- scheduler.pidfile = app_root.join('tmp/pids/rj_scheduler.pid')
164
- RJ.logger = ::Logger.new(app_root.join('log/rj_scheduler.log'), 'daily')
165
- RJ.logger.formatter = nil
166
- RJ.logger.progname = 'rj_scheduler'
167
- RJ.logger.level = Logger::INFO if ENV['VERBOSE']
168
-
169
- exit! if scheduler.work
170
- puts "rj_scheduler started."
171
- end
172
-
173
- task :stop do
174
- pidfile = app_root.join('tmp/pids/rj_scheduler.pid')
175
-
176
- unless File.exists?(pidfile)
177
- fail "Pidfile not found: #{pidfile}"
178
- else
179
- pid = open(pidfile).read.to_i
180
- begin
181
- Process.kill("TERM", pid)
182
- rescue => e
183
- $stderr.puts "Not found process: #{pid} from #{pidfile}"
184
- $stderr.puts "Removing pidfile ..."
185
- File.delete(pidfile) if File.exist?(pidfile)
186
- fail "Not found process: #{pid} from #{pidfile}"
187
- end
188
-
189
- while true
190
- begin
191
- Process.kill(0, pid)
192
- sleep 0.1
193
- rescue
194
- puts "rj_scheduler[##{pid}] stopped."
195
- break
196
- end
197
- end
198
- end
199
- end
200
-
201
- task :status do
202
- pidfile = app_root.join('tmp/pids/rj_scheduler.pid')
203
-
204
- unless File.exists?(pidfile)
205
- # puts "Pidfile not found: #{pidfile}"
206
- fail "Pidfile not found: #{pidfile}"
207
- else
208
- pid = open(pidfile).read.to_i
209
- begin
210
- raise "must return 1" unless Process.kill(0, pid) == 1
211
- puts "ok"
212
- rescue
213
- puts "Pidfile found but process not respond: #{pidfile}"
214
- puts "Removing pidfile."
215
- File.delete(pidfile) if File.exist?(pidfile)
216
- fail "Pidfile found but process not respond: #{pidfile}"
217
- end
218
- end
219
- end
34
+ desc "Start a Rabbit Jobs scheduler"
35
+ task :scheduler do
36
+ make_dirs
37
+ scheduler = RabbitJobs::Scheduler.new
38
+ scheduler.process_name = "rj_scheduler #{rails_env}"
39
+ exit(scheduler.work)
220
40
  end
221
-
222
- # desc "Start a Rabbit Jobs scheduler"
223
41
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  module RabbitJobs
4
- VERSION = "0.5.9"
4
+ VERSION = "0.6.0"
5
5
  end
data/lib/rabbit_jobs.rb CHANGED
@@ -115,7 +115,7 @@ module RabbitJobs
115
115
  def logger
116
116
  unless @logger
117
117
  @logger = Logger.new($stdout)
118
- @logger.level = Logger::WARN
118
+ @logger.level = Logger::INFO
119
119
  @logger.formatter = nil
120
120
  @logger.progname = 'rj'
121
121
  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.5.9
4
+ version: 0.6.0
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: 2013-03-06 00:00:00.000000000 Z
12
+ date: 2013-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amqp
16
- requirement: &21322560 !ruby/object:Gem::Requirement
16
+ requirement: &16471900 !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: *21322560
24
+ version_requirements: *16471900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &21321760 !ruby/object:Gem::Requirement
27
+ requirement: &16468700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *21321760
35
+ version_requirements: *16468700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rufus-scheduler
38
- requirement: &21344180 !ruby/object:Gem::Requirement
38
+ requirement: &16490220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '2.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *21344180
46
+ version_requirements: *16490220
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rails
49
- requirement: &21342820 !ruby/object:Gem::Requirement
49
+ requirement: &16485260 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '3.0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *21342820
57
+ version_requirements: *16485260
58
58
  description: Background jobs on RabbitMQ
59
59
  email:
60
60
  - lazureykis@gmail.com
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  segments:
117
117
  - 0
118
- hash: -3368029020513030695
118
+ hash: -155870681663292308
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  none: false
121
121
  requirements:
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  segments:
126
126
  - 0
127
- hash: -3368029020513030695
127
+ hash: -155870681663292308
128
128
  requirements: []
129
129
  rubyforge_project:
130
130
  rubygems_version: 1.8.11