resque-ranger 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 brianthecoder
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.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = resque-ranger
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 brianthecoder. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "resque-ranger"
8
+ gem.summary = %Q{Super fast evented daemon to process resque jobs, some built in job metrics too}
9
+ gem.description = %Q{Super fast evented daemon to process resque jobs, some built in job metrics too, just cause your app might not be on 1.9.1, your bot might be able to}
10
+ gem.email = "wbsmith83@gmail.com"
11
+ gem.homepage = "http://github.com/BrianTheCoder/resque-ranger"
12
+ gem.authors = ["brianthecoder"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ gem.add_dependency "redis", "1.0.4"
15
+ gem.add_dependency "resque", "1.8.0"
16
+ gem.add_dependency "eventmachine", "0.12.0"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "resque-ranger #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/bin/resque-ranger ADDED
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
6
+ require 'resque-ranger'
7
+ require 'choice'
8
+
9
+ @verbose = false
10
+ @very_verbose = false
11
+ @detach = false
12
+
13
+ Choice.options do
14
+ header ''
15
+ header 'Resque Ranger options:'
16
+
17
+ option :queues do
18
+ short '-q'
19
+ long '--queues=QUEUES'
20
+ desc 'List of queues to check'
21
+ cast String
22
+ default '*'
23
+ end
24
+
25
+ option :environment do
26
+ short '-e'
27
+ long '--environment=ENV'
28
+ desc 'Set rails env'
29
+ cast String
30
+ default 'development'
31
+ end
32
+
33
+ option :verbose do
34
+ short '-v'
35
+ long '--verbose'
36
+ desc 'Turn on verbose logging'
37
+ default false
38
+ action do
39
+ @verbose = true
40
+ end
41
+ end
42
+
43
+ option :very_verbose do
44
+ short '-w'
45
+ long '--very_verbose'
46
+ desc 'Turn on very verbose logging'
47
+ default false
48
+ action do
49
+ @very_verbose = true
50
+ end
51
+ end
52
+
53
+ option :interval do
54
+ short '-i'
55
+ long '--interval=INTERVAL'
56
+ desc 'Wait interval between checks'
57
+ cast Integer
58
+ default 5
59
+ end
60
+
61
+ option :workers do
62
+ short '-n'
63
+ long '--workers'
64
+ desc 'Max number of worker processes to run'
65
+ cast Integer
66
+ default 1
67
+ end
68
+
69
+ option :redis do
70
+ short '-r'
71
+ long '--redis'
72
+ desc 'Redis connection string'
73
+ cast String
74
+ default '127.0.0.1:6379/0'
75
+ end
76
+
77
+ option :detach do
78
+ short '-d'
79
+ long '--detach'
80
+ desc 'Daemonize the process, biatch!'
81
+ action do
82
+ @detach = true
83
+ end
84
+ end
85
+
86
+ option :timeout do
87
+ short '-t'
88
+ long '--timeout'
89
+ desc 'Worker timeout'
90
+ cast Integer
91
+ default 60
92
+ end
93
+
94
+ option :logger do
95
+ short '-l'
96
+ long '--logger'
97
+ desc 'Path of the log file'
98
+ cast String
99
+ default nil
100
+ end
101
+
102
+ option :pid_file do
103
+ short '-p'
104
+ long '--pid_file'
105
+ desc 'Path to the pid file'
106
+ cast String
107
+ default nil
108
+ end
109
+
110
+ separator ''
111
+ separator 'Common options: '
112
+
113
+ option :help do
114
+ long '--help'
115
+ desc 'Show this message'
116
+ end
117
+ end
118
+
119
+ ENV['RACK_ENV'] = ENV['RAILS_ENV'] = Choice.choices[:environment]
120
+
121
+ Raemon::Runner.queues = Choice.choices[:queues]
122
+ Raemon::Runner.start 5, Resque::Ranger, :detach => @detach,
123
+ :timeout => Choice.choices[:timeout],
124
+ :logger => Choice.choices[:logger],
125
+ :pid_file => Choice.choices[:pid_file]
@@ -0,0 +1,22 @@
1
+ module Raemon
2
+ class Runner < Master
3
+ def self.queues=(queues)
4
+ @queues ||= queues.to_s.split(',')
5
+ end
6
+
7
+ def self.queues; @queues end
8
+
9
+ def maintain_worker_count
10
+ # check if any jobs are available
11
+ logger.info "** Checking if any jobs are available on #{self.class.queues.inspect}"
12
+ worker = Resque::Runner.new(self.class.queues)
13
+ if worker.empty?
14
+ logger.info "** No Jobs available, sleeping for #{Choice.choices[:interval]}"
15
+ sleep Choice.choices[:interval]
16
+ else
17
+ logger.info "** Job found, starting worker"
18
+ super
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ module Resque
2
+ class Ranger
3
+ include Raemon::Worker
4
+
5
+ def start
6
+ logger.info "=> Starting worker #{Process.pid}"
7
+ end
8
+
9
+ def stop
10
+ logger.info "=> Stopping worker #{Process.pid}"
11
+
12
+ EM.stop_event_loop if EM.reactor_running?
13
+ end
14
+
15
+ def run
16
+ queues = Choice.choices[:queue].to_s.split(',')
17
+
18
+ begin
19
+ worker = Runner.new(*queues)
20
+ worker.verbose = ENV['LOGGING'] || ENV['VERBOSE']
21
+ worker.very_verbose = ENV['VVERBOSE']
22
+ rescue Resque::NoQueueError
23
+ abort "set QUEUE env var, e.g. $ QUEUE=critical,high rake resque:work"
24
+ end
25
+
26
+ puts "*** Starting worker #{worker}"
27
+
28
+ worker.work(ENV['INTERVAL'] || 5) # interval, will block
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,33 @@
1
+ module Resque
2
+ class Runner < Worker
3
+ def work(interval = 5, &block)
4
+ $0 = "resque: Starting"
5
+ startup
6
+
7
+ if not @paused and job = reserve
8
+ log "got: #{job.inspect}"
9
+ run_hook :before_fork
10
+ working_on job
11
+
12
+ procline "Processing #{job.queue} since #{Time.now.to_i}"
13
+ perform(job, &block)
14
+ exit! unless @cant_fork
15
+
16
+ done_working
17
+ @child = nil
18
+ else
19
+ break if interval.to_i == 0
20
+ log! "Sleeping for #{interval.to_i}"
21
+ procline @paused ? "Paused" : "Waiting for #{@queues.join(',')}"
22
+ sleep interval.to_i
23
+ end
24
+
25
+ ensure
26
+ unregister_worker
27
+ end
28
+
29
+ def empty?
30
+ queues.any?{|queue| Resque.size(queue).zero? }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ require 'resque'
2
+ require 'raemon'
3
+ require 'resque/ranger'
4
+ require 'resque/runner'
5
+ require 'raemon/runner'
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{resque-ranger}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["brianthecoder"]
12
+ s.date = %q{2010-04-22}
13
+ s.default_executable = %q{resque-ranger}
14
+ s.description = %q{Super fast evented daemon to process resque jobs, some built in job metrics too, just cause your app might not be on 1.9.1, your bot might be able to}
15
+ s.email = %q{wbsmith83@gmail.com}
16
+ s.executables = ["resque-ranger"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/resque-ranger",
29
+ "lib/raemon/runner.rb",
30
+ "lib/resque-ranger.rb",
31
+ "lib/resque/ranger.rb",
32
+ "lib/resque/runner.rb",
33
+ "resque-ranger.gemspec",
34
+ "test/helper.rb",
35
+ "test/test_resque-ranger.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/BrianTheCoder/resque-ranger}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.6}
41
+ s.summary = %q{Super fast evented daemon to process resque jobs, some built in job metrics too}
42
+ s.test_files = [
43
+ "test/helper.rb",
44
+ "test/test_resque-ranger.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
53
+ s.add_runtime_dependency(%q<redis>, ["= 1.0.4"])
54
+ s.add_runtime_dependency(%q<resque>, ["= 1.8.0"])
55
+ s.add_runtime_dependency(%q<eventmachine>, ["= 0.12.0"])
56
+ else
57
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
58
+ s.add_dependency(%q<redis>, ["= 1.0.4"])
59
+ s.add_dependency(%q<resque>, ["= 1.8.0"])
60
+ s.add_dependency(%q<eventmachine>, ["= 0.12.0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
64
+ s.add_dependency(%q<redis>, ["= 1.0.4"])
65
+ s.add_dependency(%q<resque>, ["= 1.8.0"])
66
+ s.add_dependency(%q<eventmachine>, ["= 0.12.0"])
67
+ end
68
+ end
69
+
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'resque-ranger'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestResqueRanger < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque-ranger
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - brianthecoder
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-22 00:00:00 -05:00
18
+ default_executable: resque-ranger
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: redis
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 1
41
+ - 0
42
+ - 4
43
+ version: 1.0.4
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: resque
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 1
55
+ - 8
56
+ - 0
57
+ version: 1.8.0
58
+ type: :runtime
59
+ version_requirements: *id003
60
+ - !ruby/object:Gem::Dependency
61
+ name: eventmachine
62
+ prerelease: false
63
+ requirement: &id004 !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ - 12
70
+ - 0
71
+ version: 0.12.0
72
+ type: :runtime
73
+ version_requirements: *id004
74
+ description: Super fast evented daemon to process resque jobs, some built in job metrics too, just cause your app might not be on 1.9.1, your bot might be able to
75
+ email: wbsmith83@gmail.com
76
+ executables:
77
+ - resque-ranger
78
+ extensions: []
79
+
80
+ extra_rdoc_files:
81
+ - LICENSE
82
+ - README.rdoc
83
+ files:
84
+ - .document
85
+ - .gitignore
86
+ - LICENSE
87
+ - README.rdoc
88
+ - Rakefile
89
+ - VERSION
90
+ - bin/resque-ranger
91
+ - lib/raemon/runner.rb
92
+ - lib/resque-ranger.rb
93
+ - lib/resque/ranger.rb
94
+ - lib/resque/runner.rb
95
+ - resque-ranger.gemspec
96
+ - test/helper.rb
97
+ - test/test_resque-ranger.rb
98
+ has_rdoc: true
99
+ homepage: http://github.com/BrianTheCoder/resque-ranger
100
+ licenses: []
101
+
102
+ post_install_message:
103
+ rdoc_options:
104
+ - --charset=UTF-8
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project:
124
+ rubygems_version: 1.3.6
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: Super fast evented daemon to process resque jobs, some built in job metrics too
128
+ test_files:
129
+ - test/helper.rb
130
+ - test/test_resque-ranger.rb