rabbit_jobs 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,7 @@ module RabbitJobs
14
14
 
15
15
  def prepare_connection
16
16
  if !AMQP.connection || AMQP.connection.closed?
17
- RJ.logger.info("rj[##{Process.pid}] Connecting to #{RJ.config.servers.first.to_s}...")
17
+ RJ.logger.info("Connecting to #{RJ.config.servers.first.to_s}...")
18
18
  AMQP.connection = AMQP.connect(RJ.config.servers.first, auto_recovery: true)
19
19
  init_auto_recovery
20
20
  end
@@ -32,15 +32,15 @@ module RabbitJobs
32
32
  HOSTS_DEAD.clear
33
33
  HOSTS_FAILED.clear
34
34
  url = url_from_opts opts
35
- RJ.logger.warn "rj[##{Process.pid}] Connection to #{url} recovered."
35
+ RJ.logger.warn "Connection to #{url} recovered."
36
36
  end
37
37
 
38
38
  AMQP.connection.on_open do |conn, opts|
39
- RJ.logger.info "rj[##{Process.pid}] Connected."
39
+ RJ.logger.info "Connected."
40
40
  end
41
41
 
42
42
  # AMQP.connection.before_recovery do |conn, opts|
43
- # RJ.logger.info "rj[##{Process.pid}] before_recovery"
43
+ # RJ.logger.info "before_recovery"
44
44
  # end
45
45
 
46
46
  # AMQP.connection.on_possible_authentication_failure do |conn, opts|
@@ -87,10 +87,10 @@ module RabbitJobs
87
87
 
88
88
  def reconnect_to(url)
89
89
  if AMQP.connection
90
- RJ.logger.warn "rj[##{Process.pid}] Trying to reconnect to #{url}..."
90
+ RJ.logger.warn "Trying to reconnect to #{url}..."
91
91
  AMQP.connection.reconnect_to(url, 2)
92
92
  else
93
- RJ.logger.warn "rj[##{Process.pid}] Trying to connect to #{url}..."
93
+ RJ.logger.warn "Trying to connect to #{url}..."
94
94
  AMQP.connection = AMQP.connect(url, auto_recovery: true)
95
95
  init_auto_recovery
96
96
  end
@@ -19,10 +19,10 @@ module RabbitJobs::Job
19
19
  def run_perform
20
20
  begin
21
21
  start_time = Time.now
22
- RJ.logger.info "rj_worker[##{Process.pid}] performing #{self.to_ruby_string} at #{start_time.utc}"
22
+ RJ.logger.info "Started to perform #{self.to_ruby_string}"
23
23
  self.class.perform(*params)
24
24
  execution_time = Time.now - start_time
25
- RJ.logger.info "rj_worker[##{Process.pid}] processed #{self.to_ruby_string} in #{execution_time} seconds."
25
+ RJ.logger.info " Job completed #{self.to_ruby_string} in #{execution_time} seconds."
26
26
  rescue
27
27
  RJ.logger.warn $!.message
28
28
  RJ.logger.warn(self.to_ruby_string)
@@ -116,11 +116,11 @@ module RabbitJobs::Job
116
116
  RJ.logger.error "Cannot find job class '#{encoded['class']}'"
117
117
  :not_found
118
118
  rescue JSON::ParserError
119
- RJ.logger.error "rj[##{Process.pid}] Cannot initialize job. Json parsing error."
120
- RJ.logger.error "rj[##{Process.pid}] Data received: #{payload.inspect}"
119
+ RJ.logger.error "Cannot initialize job. Json parsing error."
120
+ RJ.logger.error "Data received: #{payload.inspect}"
121
121
  :parsing_error
122
122
  rescue
123
- RJ.logger.warn "rj[##{Process.pid}] Cannot initialize job."
123
+ RJ.logger.warn "Cannot initialize job."
124
124
  RJ.logger.warn $!.message
125
125
  RJ.logger.warn RJ::Util.cleanup_backtrace($!.backtrace).join("\n")
126
126
  RJ.logger.warn "Data received: #{payload.inspect}"
@@ -98,7 +98,7 @@ module RabbitJobs
98
98
  check_shutdown = Proc.new {
99
99
  if @shutdown
100
100
  RJ.stop
101
- RJ.logger.info "rj_scheduler[##{Process.pid}] stopped."
101
+ RJ.logger.info "Stopped."
102
102
 
103
103
  File.delete(self.pidfile) if self.pidfile
104
104
  end
@@ -114,7 +114,7 @@ module RabbitJobs
114
114
  check_shutdown.call
115
115
  end
116
116
 
117
- RJ.logger.info "rj_scheduler[##{Process.pid}] started."
117
+ RJ.logger.info "Started."
118
118
  end
119
119
  rescue => e
120
120
  error = $!
@@ -131,7 +131,7 @@ module RabbitJobs
131
131
  end
132
132
 
133
133
  def shutdown
134
- RJ.logger.info "rj_scheduler[##{Process.pid}] stopping..."
134
+ RJ.logger.info "Stopping..."
135
135
  @shutdown = true
136
136
  end
137
137
 
@@ -42,7 +42,9 @@ namespace :rj do
42
42
  worker.process_name = "rj_worker #{worker_name}##{worker_num} #{rails_env} [#{queues.join(',')}]"
43
43
  worker.pidfile = app_root.join("tmp/pids/rj_worker_#{rails_env}_#{worker_name}_#{worker_num}.pid")
44
44
  RJ.logger = ::Logger.new(app_root.join("log/rj_worker_#{rails_env}_#{worker_name}_#{worker_num}.log"), 'daily')
45
- # RJ.logger.level = ENV['VERBOSE'] ? Logger::INFO : Logger::WARN
45
+ RJ.logger.formatter = nil
46
+ RJ.logger.progname = 'rj_worker'
47
+ RJ.logger.level = Logger::INFO if ENV['VERBOSE']
46
48
  puts "Starting #{worker_name}##{worker_num}"
47
49
 
48
50
  # завершаем копию процесса, если воркер уже отработал
@@ -162,7 +164,9 @@ namespace :rj do
162
164
  scheduler.background = true
163
165
  scheduler.pidfile = app_root.join('tmp/pids/rj_scheduler.pid')
164
166
  RJ.logger = ::Logger.new(app_root.join('log/rj_scheduler.log'), 'daily')
165
- # RJ.logger.level = ENV['VERBOSE'] ? Logger::INFO : Logger::WARN
167
+ RJ.logger.formatter = nil
168
+ RJ.logger.progname = 'rj_scheduler'
169
+ RJ.logger.level = Logger::INFO if ENV['VERBOSE']
166
170
 
167
171
  exit! if scheduler.work
168
172
  puts "rj_scheduler started."
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  module RabbitJobs
4
- VERSION = "0.4.4"
4
+ VERSION = "0.4.5"
5
5
  end
@@ -40,8 +40,8 @@ module RabbitJobs
40
40
  check_shutdown = Proc.new {
41
41
  if @shutdown
42
42
  RJ.stop
43
- RJ.logger.info "rj_worker[##{Process.pid}] processed jobs: #{processed_count}."
44
- RJ.logger.info "rj_worker[##{Process.pid}] stopped."
43
+ RJ.logger.info "Processed jobs: #{processed_count}."
44
+ RJ.logger.info "Stopped."
45
45
 
46
46
  File.delete(self.pidfile) if self.pidfile && File.exists?(self.pidfile)
47
47
  # RJ.logger.close
@@ -54,7 +54,7 @@ module RabbitJobs
54
54
  queues.each do |routing_key|
55
55
  AMQP.channel.prefetch(1)
56
56
  AMQP.channel.queue(RJ.config.queue_name(routing_key), RJ.config[:queues][routing_key]) { |queue, declare_ok|
57
- RJ.logger.info "rj_worker[##{Process.pid}] subscribed to #{RJ.config.queue_name(routing_key)} (#{declare_ok.to_i + 1})"
57
+ RJ.logger.info "Subscribed to #{RJ.config.queue_name(routing_key)}(#{declare_ok.to_i + 1})"
58
58
 
59
59
  explicit_ack = !!RJ.config[:queues][routing_key][:ack]
60
60
 
@@ -70,7 +70,7 @@ module RabbitJobs
70
70
  metadata.ack if explicit_ack
71
71
  else
72
72
  if @job.expired?
73
- RJ.logger.warn "rj_worker[##{Process.pid}] Job expired: #{@job.to_ruby_string}"
73
+ RJ.logger.warn "Job expired: #{@job.to_ruby_string}"
74
74
  else
75
75
  @job.run_perform
76
76
  processed_count += 1
@@ -95,7 +95,7 @@ module RabbitJobs
95
95
  check_shutdown.call
96
96
  end
97
97
 
98
- RJ.logger.info "rj_worker[##{Process.pid}] started."
98
+ RJ.logger.info "Started."
99
99
  end
100
100
  rescue
101
101
  error = $!
data/lib/rabbit_jobs.rb CHANGED
@@ -98,7 +98,9 @@ module RabbitJobs
98
98
  def logger
99
99
  unless @logger
100
100
  @logger = Logger.new($stdout)
101
- # @logger.level = Logger::WARN
101
+ @logger.level = Logger::WARN
102
+ @logger.formatter = nil
103
+ @logger.progname = 'rj'
102
104
  end
103
105
  @logger
104
106
  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.4.4
4
+ version: 0.4.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amqp
16
- requirement: &6815860 !ruby/object:Gem::Requirement
16
+ requirement: &10959520 !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: *6815860
24
+ version_requirements: *10959520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &6814800 !ruby/object:Gem::Requirement
27
+ requirement: &10958660 !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: *6814800
35
+ version_requirements: *10958660
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rufus-scheduler
38
- requirement: &6814000 !ruby/object:Gem::Requirement
38
+ requirement: &10957860 !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: *6814000
46
+ version_requirements: *10957860
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rails
49
- requirement: &6812800 !ruby/object:Gem::Requirement
49
+ requirement: &10957020 !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: *6812800
57
+ version_requirements: *10957020
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: 4510837792608330592
118
+ hash: 1163928231498999905
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: 4510837792608330592
127
+ hash: 1163928231498999905
128
128
  requirements: []
129
129
  rubyforge_project:
130
130
  rubygems_version: 1.8.11