resque_stuck_queue 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWE1YzA3NjU4NjE1NGQ3ZjQ4OGMwNzRlZDE3Nzk4ZDhlOTc2YjM4YQ==
4
+ MGU4NWIyMWEyMjMyMWQwYTVjYjUxYTI5YjlmZWUwMmM0ZWYxMzhlZg==
5
5
  data.tar.gz: !binary |-
6
- YTBiNGVhN2U5ZjYzMzkwOWJkNDc4Y2ViZTcyOTFjOWNlMjJmZDdiNQ==
6
+ NzBlMGViOGVmNzMzZTU1ZjczMzNiZDU4MjU3YTViNWNmY2YwNzU3Mw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZmMxMzgzYTRhM2QyNDg4YTAyYjcxMTE4Y2RmYmNhMWJjNTBlZGVmOGMxNWRk
10
- MTYxZTEyN2MyODc1NTNiODljYWRlZWUxZDgzZGExZjM5NzFkZjAzYTU5Y2M2
11
- YmQyMDc0ZGFjOTlhYWFlNTM4YzFmY2M3NTI2ZTliYjcyZTA2NzY=
9
+ Mzg5ZTUyOWVhMjQzYTkwNmQ3YmQ2NDc0MDAzZGU4NWZhNTkxYWE3ODM0N2Jk
10
+ NzBlYTdlOTliMTNkOGIyYzc2ZDU2MmU4ZmJlYzllNGVhZjExNzk4MWY0Mzlj
11
+ MGRjM2FlNmNlY2RkZWE4NGRiNTJmN2IxOTY5M2EyZDhkZjFlMWQ=
12
12
  data.tar.gz: !binary |-
13
- YWY2ODg5NGEwN2Q2ZGI3ODcyMWRmZjk5OGU3NTA0ZDgyMDkxNmQ1NzIzZTM3
14
- M2ExODE3NDA4NjNiMTE0ZDE5ZDdiNWEyMDE3ZjFhNDYyZTgzYTEzNTM0M2I3
15
- YWEzMjc0MjFmMDFlZGNkOTk3M2YwNWY3ZjBlZjY4MWQzMzQzOTI=
13
+ Yjc3ZWJmN2Y3OGM3NDk0ODMzMGJjNzcxMWIzMGRkY2Q2NWQxNTdiNGU3OTQ1
14
+ NDU3NmRmNDMxMmRhYzk1ZmU1OTViYTJhZmY5ZjkwNGMxYTEwZjY5N2QzZmI1
15
+ ZThmYWMyYWE5OTgzNGRjNGJiMGZiMDczOWQ4ZmRiNmZkMDdmNWM=
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
- ## Resque stuck queue
1
+ # Resque stuck queue
2
2
 
3
- Ever run into that? Sucks, eh?
3
+ ## Why?
4
4
 
5
- This should enable a way to fire some handler when jobs aren't occurring within a certain timeframe.
5
+ This is to be used to satisfy an ops problem. There have been cases resque processes would stop processing jobs for unknown reasons. Other times resque wouldn't be running entirely due to deploy problems architecture/human error issues. Or on a different note, resque could be highly backed up and won't process jobs because it's too busy. This enables gaining a little insight into those issues.
6
+
7
+ ## What is it?
8
+
9
+ If resque doesn't run jobs within a certain timeframe, it will trigger a pre-defined handler of your choice. You can use this to send an email, pager duty, add more resque workers, restart resque, send you a txt...whatever suits you.
6
10
 
7
11
  ## How it works
8
12
 
@@ -25,12 +29,12 @@ Resque::StuckQueue.config[:heartbeat] = 5.minutes
25
29
  # since there is an realistic and acceptable lag for job queues, set this to how much you're
26
30
  # willing to accept between the current time and when the last hearbeat job went through.
27
31
  #
28
- # obviously, take the heartbeat into consideration when setting this
32
+ # take the heartbeat into consideration when setting this (it will fire 10 hours + 5 minutes with above heartbeat).
29
33
  Resque::StuckQueue.config[:trigger_timeout] = 10.hours
30
34
 
31
35
  # what gets triggered when resque-stuck-queue will detect the latest heartbeat is older than the trigger_timeout time set above.
32
36
  #
33
- # triggering will update the key, so you'll have to wait the trigger_timeout again
37
+ # triggering will update the key, so you'll have to wait the trigger_timeout again
34
38
  # in order for it to trigger again even if workers are still stale.
35
39
  Resque::StuckQueue.config[:handler] = proc { send_email }
36
40
 
@@ -67,7 +71,33 @@ Note though, the resque-stuck threads will live alongside the app server process
67
71
 
68
72
  * Run this as a daemon somewhere alongside the app/in your setup.
69
73
 
70
- <!-- TODO example -->
74
+ Contrived example:
75
+
76
+ <pre>
77
+
78
+ # put this in lib/tasks/resque_stuck_queue.rb
79
+
80
+ require 'resque_stuck_queue'
81
+
82
+ namespace :resque do
83
+ desc "Start a Resque-stuck daemon"
84
+ task :stuck_queue do
85
+
86
+ Resque::StuckQueue.config[:heartbeat] = 10.minutes
87
+ Resque::StuckQueue.config[:trigger_timeout] = 1.hour
88
+ Resque::StuckQueue.config[:handler] = proc { $stderr.puts("resque wonky!") }
89
+
90
+ Resque::StuckQueue.start # blocking operation, daemon running
91
+ end
92
+ end
93
+
94
+ # then:
95
+
96
+ $ bundle exec rake --trace resque:stuck_queue
97
+
98
+ # you can run this under god for example @ https://gist.github.com/shaiguitar/298935953d91faa6bd4e
99
+
100
+ </pre>
71
101
 
72
102
  ## Tests
73
103
 
data/THOUGHTS CHANGED
@@ -3,30 +3,10 @@ other resources:
3
3
  http://vitobotta.com/resque-automatically-kill-stuck-workers-retry-failed-jobs/#sthash.oQsaNeb5.dpbs
4
4
  http://stackoverflow.com/questions/10757758/find-out-if-a-resque-job-is-still-running-and-kill-it-if-its-stuck
5
5
 
6
- heartbeat?
7
-
8
- redis scenario
9
- different processes (cant share state in Resque memory etc.)
10
- different boxes! (redis is shared state)
11
- if this is included in servers, you have clusters os unicorn/mongrel etc,
12
- ensure it works across multiple running instances of this lib?
13
-
14
- Thing.setup_checker_thread
15
- Thing.enqueue_repeating_refresh_job
16
-
17
- reproduce the error and integrate test like that
18
-
19
6
  ## TODOS
20
7
 
21
- verify @config options, raise if no handler, etc.
22
-
23
- - use locks to only notify/trigger once in case this is used in a server-cluster type environment adn you only want the handler triggered once
24
-
25
- - resque in stuck (t state process) SIGSTOP sticks up the checker thread?
26
- or if not running
27
-
28
- - ensure it only runs from the server box and not the resque box??
29
- (the deploy restarts the server but not resque workers)
30
-
8
+ verifications of @config options: raise if no handler, etc.
9
+ add daemon example to readme
31
10
  add a 'resque_stuck_queue/tasks' bit? See tres eg
32
11
  require 'resque/stuck_queue' instead?
12
+ ensure the logging gets flushed into log file correctly? (integration with god?)
@@ -0,0 +1 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), "..","resque_stuck_queue")
@@ -1,12 +1,12 @@
1
1
  require "resque_stuck_queue/version"
2
2
 
3
+ # TODO move this require into a configurable?
4
+ require 'resque'
5
+
3
6
  # TODO rm redis-mutex dep and just do the setnx locking here
4
7
  require 'redis-mutex'
5
8
  Redis::Classy.db = Resque.redis
6
9
 
7
- # TODO move this require into a configurable?
8
- require 'resque'
9
-
10
10
  require 'logger'
11
11
 
12
12
  module Resque
@@ -51,13 +51,6 @@ module Resque
51
51
  end
52
52
  end
53
53
 
54
- def stop_in_background
55
- Thread.new do
56
- Thread.current.abort_on_exception = config[:abort_on_exception]
57
- self.start
58
- end
59
- end
60
-
61
54
  # call this after setting config. once started you should't be allowed to modify it
62
55
  def start
63
56
  @running = true
@@ -1,5 +1,5 @@
1
1
  module Resque
2
2
  module StuckQueue
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -15,7 +15,7 @@ class TestCollision < Minitest::Test
15
15
  p4 = fork { Resque.redis.client.reconnect; run_resque_stuck_daemon; }
16
16
 
17
17
  Thread.new {
18
- sleep 5 # let test run and trigger once occur (according to time below)
18
+ sleep 4 # let test run and trigger once occur (according to time below)
19
19
  `kill -9 #{p1}`
20
20
  `kill -9 #{p2}`
21
21
  `kill -9 #{p3}`
@@ -33,7 +33,7 @@ class TestCollision < Minitest::Test
33
33
  def run_resque_stuck_daemon
34
34
  Resque::StuckQueue.config[:heartbeat] = 1
35
35
  Resque::StuckQueue.config[:abort_on_exception] = true
36
- Resque::StuckQueue.config[:trigger_timeout] = 4
36
+ Resque::StuckQueue.config[:trigger_timeout] = 3
37
37
  Resque::StuckQueue.config[:handler] = proc { Resque.redis.incr("test-incr-key") }
38
38
  Resque::StuckQueue.start
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_stuck_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shai Rosenfeld
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-06 00:00:00.000000000 Z
11
+ date: 2014-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-mutex
@@ -66,6 +66,7 @@ files:
66
66
  - README.md
67
67
  - Rakefile
68
68
  - THOUGHTS
69
+ - lib/resque/stuck_queue.rb
69
70
  - lib/resque_stuck_queue.rb
70
71
  - lib/resque_stuck_queue/version.rb
71
72
  - resque_stuck_queue.gemspec