insque 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,4 @@
1
1
  Insque.sender = '<%= sender_name %>'
2
2
  REDIS_CONFIG = YAML.load(File.open("#{Rails.root}/config/redis.yml"))[Rails.env]
3
- $redis = Redis.new(:host => REDIS_CONFIG["host"], :port => REDIS_CONFIG["port"])
4
- Insque.redis = $redis
3
+ Insque.redis_config = { :host => REDIS_CONFIG["host"], :port => REDIS_CONFIG["port"] }
5
4
  Insque.debug = true
6
- if defined?(PhusionPassenger)
7
- PhusionPassenger.on_event(:starting_worker_process) do |forked|
8
- if forked
9
- $redis = Redis.new(:host => REDIS_CONFIG["host"], :port => REDIS_CONFIG["port"])
10
- Insque.redis = $redis
11
- end
12
- end
13
- end
@@ -1,3 +1,3 @@
1
1
  module Insque
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
data/lib/insque.rb CHANGED
@@ -7,8 +7,9 @@ module Insque
7
7
  @debug = debug
8
8
  end
9
9
 
10
- def self.redis= redis
11
- @redis = redis
10
+ def self.redis_config= redis
11
+ @redis_config = redis
12
+ @redis = Redis.new @redis_config
12
13
  @redis.select 7
13
14
  end
14
15
 
@@ -37,10 +38,13 @@ module Insque
37
38
  end
38
39
 
39
40
  def self.listen worker_name=''
40
- @redis.sadd 'insque_inboxes', @inbox
41
+ redis = Redis.new redis
42
+ redis.select 7
43
+
44
+ redis.sadd 'insque_inboxes', @inbox
41
45
  log "#{worker_name} START LISTENING #{@inbox}"
42
46
  loop do
43
- message = @redis.brpoplpush(@inbox, @processing, 0)
47
+ message = redis.brpoplpush(@inbox, @processing, 0)
44
48
  log "#{worker_name} RECEIVING: #{message}" if @debug
45
49
  begin
46
50
  parsed_message = JSON.parse message
@@ -50,17 +54,20 @@ module Insque
50
54
  log e.inspect
51
55
  log e.backtrace
52
56
  end
53
- @redis.lrem @processing, 0, message
57
+ redis.lrem @processing, 0, message
54
58
  end
55
59
  end
56
60
 
57
61
  def self.janitor
62
+ redis = Redis.new redis
63
+ redis.select 7
64
+
58
65
  loop do
59
- @redis.watch @processing
66
+ redis.watch @processing
60
67
  errors = []
61
68
  restart = []
62
69
  delete = []
63
- @redis.lrange(@processing, 0, -1).each do |m|
70
+ redis.lrange(@processing, 0, -1).each do |m|
64
71
  begin
65
72
  parsed_message = JSON.parse(m)
66
73
  if parsed_message['restarted_at'] && DateTime.parse(parsed_message['restarted_at']) < 1.hour.ago.utc
@@ -74,7 +81,7 @@ module Insque
74
81
  log "========== JANITOR_BROKEN_MESSAGE: #{m} =========="
75
82
  end
76
83
  end
77
- result = @redis.multi do |r|
84
+ result = redis.multi do |r|
78
85
  restart.each {|m| r.lpush @inbox, m.to_json }
79
86
  delete.each {|m| r.lrem @processing, 0, m }
80
87
  end
@@ -89,7 +96,7 @@ module Insque
89
96
  end
90
97
  end
91
98
 
92
- private
99
+ private
93
100
  def self.log message
94
101
  print "#{Time.now.utc} #{message}\n"
95
102
  STDOUT.flush if @debug
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insque
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: