external_resque_worker 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,38 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: external_resque_worker
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Gordon
14
14
  - Joel Meador
15
15
  - Chris Moore
16
+ - Jason Gladish
16
17
  autorequire:
17
18
  bindir: bin
18
19
  cert_chain: []
19
20
 
20
- date: 2011-12-15 00:00:00 -05:00
21
+ date: 2012-01-04 00:00:00 -05:00
21
22
  default_executable:
22
23
  dependencies: []
23
24
 
24
25
  description: Easy way to manage running one or more resque processes during testing
25
- email: matt@expectedbehavior.com
26
+ email: matt@expectedbehavior.com joel@expectedbehavior.com jason@expectedbehavior.com chris@monoclesoftware.com
26
27
  executables: []
27
28
 
28
29
  extensions: []
29
30
 
30
31
  extra_rdoc_files: []
31
32
 
32
- files:
33
- - README.md
34
- - MIT-LICENSE
35
- - lib/external_resque_worker.rb
33
+ files: []
34
+
36
35
  has_rdoc: true
37
36
  homepage: http://expectedbehavior.com
38
37
  licenses: []
@@ -1,20 +0,0 @@
1
- Copyright (c) 2010 [Expected Behavior, LLC]
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1 +0,0 @@
1
- we totally got the original code from somehwere, but I don't know where
@@ -1,92 +0,0 @@
1
- class ExternalResqueWorker
2
- DEFAULT_STARTUP_TIMEOUT = 1.minute
3
-
4
- attr_accessor :pid, :startup_timeout
5
-
6
- def initialize
7
- start
8
- end
9
-
10
- def start
11
- raise "PEDANTICALLY CODED TO ONLY WORK IN TEST ENV" unless Rails.env.test?
12
- install_hooks_on_startup
13
- if self.pid = fork
14
- Process.detach(pid)
15
- wait_for_worker_to_start
16
- else
17
- STDOUT.reopen(File.open("#{Rails.root}/log/external_resque_worker.log", "a+")) # stops it from giving us the extra test output
18
- start_child
19
- end
20
- end
21
-
22
- def self.kill_all_existing_workers
23
- while Resque::Worker.all.size > 0
24
- Resque::Worker.all.each do |w|
25
- Process.kill("TERM", w.pid) rescue nil
26
- w.prune_dead_workers
27
- end
28
- end
29
- end
30
-
31
- def install_hooks_on_startup
32
- install_pause_on_start_hook
33
- end
34
-
35
- def process_all
36
- unpause
37
- sleep 1 until done?
38
- pause
39
- end
40
-
41
- def pause(pid = self.pid)
42
- Process.kill("USR2", pid)
43
- end
44
-
45
- def unpause
46
- Process.kill("CONT", pid)
47
- end
48
-
49
- private
50
-
51
- def done?
52
- all_queues_empty = Resque.queues.all? do |queue|
53
- Resque.peek(queue).blank?
54
- end
55
- all_queues_empty and Resque::Worker.working.empty?
56
- end
57
-
58
- def start_parent
59
- at_exit do
60
- Process.kill("KILL", pid) if pid
61
- end
62
- end
63
-
64
- def start_child
65
- # Array form of exec() is required here, otherwise the worker is not a direct
66
- # child process of test.
67
- # If it's not the direct child process then the PID returned from fork() is
68
- # wrong, which means we can't communicate with the worker.
69
- exec('rake', "--silent", 'resque:work', "QUEUE=*", "INTERVAL=0.25", "RAILS_ENV=test")
70
- end
71
-
72
- def wait_for_worker_to_start
73
- self.startup_timeout ||= DEFAULT_STARTUP_TIMEOUT
74
- start = Time.now.to_i
75
- while (Time.now.to_i - start) < startup_timeout
76
- return if worker_started?
77
- sleep 1
78
- end
79
-
80
- raise "Timeout while waiting for the worker to start. Waited #{startup_timeout} seconds."
81
- end
82
-
83
- def worker_started?
84
- Resque.workers.any? { |worker| worker.pid == self.pid }
85
- end
86
-
87
- def install_pause_on_start_hook
88
- Resque.before_first_fork do
89
- pause(Process.pid)
90
- end unless Resque.before_first_fork
91
- end
92
- end