brianjlandau-resque-scheduler 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,115 @@
1
+ # Redis configuration file example
2
+
3
+ # By default Redis does not run as a daemon. Use 'yes' if you need it.
4
+ # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
5
+ daemonize yes
6
+
7
+ # When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
8
+ # You can specify a custom pid file location here.
9
+ pidfile ./test/redis-test.pid
10
+
11
+ # Accept connections on the specified port, default is 6379
12
+ port 9736
13
+
14
+ # If you want you can bind a single interface, if the bind option is not
15
+ # specified all the interfaces will listen for connections.
16
+ #
17
+ # bind 127.0.0.1
18
+
19
+ # Close the connection after a client is idle for N seconds (0 to disable)
20
+ timeout 300
21
+
22
+ # Save the DB on disk:
23
+ #
24
+ # save <seconds> <changes>
25
+ #
26
+ # Will save the DB if both the given number of seconds and the given
27
+ # number of write operations against the DB occurred.
28
+ #
29
+ # In the example below the behaviour will be to save:
30
+ # after 900 sec (15 min) if at least 1 key changed
31
+ # after 300 sec (5 min) if at least 10 keys changed
32
+ # after 60 sec if at least 10000 keys changed
33
+ save 900 1
34
+ save 300 10
35
+ save 60 10000
36
+
37
+ # The filename where to dump the DB
38
+ dbfilename dump.rdb
39
+
40
+ # For default save/load DB in/from the working directory
41
+ # Note that you must specify a directory not a file name.
42
+ dir ./test/
43
+
44
+ # Set server verbosity to 'debug'
45
+ # it can be one of:
46
+ # debug (a lot of information, useful for development/testing)
47
+ # notice (moderately verbose, what you want in production probably)
48
+ # warning (only very important / critical messages are logged)
49
+ loglevel debug
50
+
51
+ # Specify the log file name. Also 'stdout' can be used to force
52
+ # the demon to log on the standard output. Note that if you use standard
53
+ # output for logging but daemonize, logs will be sent to /dev/null
54
+ logfile stdout
55
+
56
+ # Set the number of databases. The default database is DB 0, you can select
57
+ # a different one on a per-connection basis using SELECT <dbid> where
58
+ # dbid is a number between 0 and 'databases'-1
59
+ databases 16
60
+
61
+ ################################# REPLICATION #################################
62
+
63
+ # Master-Slave replication. Use slaveof to make a Redis instance a copy of
64
+ # another Redis server. Note that the configuration is local to the slave
65
+ # so for example it is possible to configure the slave to save the DB with a
66
+ # different interval, or to listen to another port, and so on.
67
+
68
+ # slaveof <masterip> <masterport>
69
+
70
+ ################################## SECURITY ###################################
71
+
72
+ # Require clients to issue AUTH <PASSWORD> before processing any other
73
+ # commands. This might be useful in environments in which you do not trust
74
+ # others with access to the host running redis-server.
75
+ #
76
+ # This should stay commented out for backward compatibility and because most
77
+ # people do not need auth (e.g. they run their own servers).
78
+
79
+ # requirepass foobared
80
+
81
+ ################################### LIMITS ####################################
82
+
83
+ # Set the max number of connected clients at the same time. By default there
84
+ # is no limit, and it's up to the number of file descriptors the Redis process
85
+ # is able to open. The special value '0' means no limts.
86
+ # Once the limit is reached Redis will close all the new connections sending
87
+ # an error 'max number of clients reached'.
88
+
89
+ # maxclients 128
90
+
91
+ # Don't use more memory than the specified amount of bytes.
92
+ # When the memory limit is reached Redis will try to remove keys with an
93
+ # EXPIRE set. It will try to start freeing keys that are going to expire
94
+ # in little time and preserve keys with a longer time to live.
95
+ # Redis will also try to remove objects from free lists if possible.
96
+ #
97
+ # If all this fails, Redis will start to reply with errors to commands
98
+ # that will use more memory, like SET, LPUSH, and so on, and will continue
99
+ # to reply to most read-only commands like GET.
100
+ #
101
+ # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
102
+ # 'state' server or cache, not as a real DB. When Redis is used as a real
103
+ # database the memory usage will grow over the weeks, it will be obvious if
104
+ # it is going to use too much memory in the long run, and you'll have the time
105
+ # to upgrade. With maxmemory after the limit is reached you'll start to get
106
+ # errors for write operations, and this may even lead to DB inconsistency.
107
+
108
+ # maxmemory <bytes>
109
+
110
+ ############################### ADVANCED CONFIG ###############################
111
+
112
+ # Glue small output buffers together in order to send small replies in a
113
+ # single TCP packet. Uses a bit more CPU but most of the times it is a win
114
+ # in terms of number of queries per second. Use 'yes' if unsure.
115
+ glueoutputbuf yes
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ # Pull in the server test_helper from resque
4
+ require 'resque/server/test_helper.rb'
5
+
6
+ context "on GET to /schedule" do
7
+ setup { get "/schedule" }
8
+
9
+ should_respond_with_success
10
+ end
11
+
12
+ context "on GET to /schedule with scheduled jobs" do
13
+ setup do
14
+ ENV['rails_env'] = 'production'
15
+ Resque.schedule = {:some_ivar_job => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp", 'rails_env' => 'production'}}
16
+ Resque::Scheduler.load_schedule!
17
+ get "/schedule"
18
+ end
19
+
20
+ should_respond_with_success
21
+
22
+ test 'see the scheduled job' do
23
+ assert last_response.body.include?('SomeIvarJob')
24
+ end
25
+ end
26
+
27
+ context "on GET to /delayed" do
28
+ setup { get "/delayed" }
29
+
30
+ should_respond_with_success
31
+ end
@@ -0,0 +1,100 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ module ::Resque
4
+ def self.reload_schedule!
5
+ self.schedule = {:some_ivar_job2 => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/2"}}
6
+ end
7
+ end
8
+
9
+ class Resque::SchedulerTest < Test::Unit::TestCase
10
+
11
+ class FakeJob
12
+ def self.scheduled(queue, klass, *args); end
13
+ end
14
+
15
+ def setup
16
+ Resque::Scheduler.clear_schedule!
17
+ end
18
+
19
+ def test_enqueue_from_config_puts_stuff_in_the_resque_queue_without_class_loaded
20
+ Resque::Job.stubs(:create).once.returns(true).with('joes_queue', 'BigJoesJob', '/tmp')
21
+ Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'BigJoesJob', 'args' => "/tmp", 'queue' => 'joes_queue')
22
+ end
23
+
24
+ def test_enqueue_from_config_puts_stuff_in_the_resque_queue
25
+ Resque::Job.stubs(:create).once.returns(true).with(:ivar, 'SomeIvarJob', '/tmp')
26
+ Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp")
27
+ end
28
+
29
+ def test_enqueue_from_config_with_custom_class_job_in_the_resque_queue
30
+ FakeJob.stubs(:scheduled).once.returns(true).with(:ivar, 'SomeIvarJob', '/tmp')
31
+ Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'SomeIvarJob', 'custom_job_class' => 'Resque::SchedulerTest::FakeJob', 'args' => "/tmp")
32
+ end
33
+
34
+ def test_enqueue_from_config_puts_stuff_in_the_resque_queue_when_env_match
35
+ # The job should be loaded : its rails_env config matches the RAILS_ENV variable:
36
+ ENV['RAILS_ENV'] = 'production'
37
+ assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
38
+
39
+ Resque.schedule = {:some_ivar_job => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp", 'rails_env' => 'production'}}
40
+ Resque::Scheduler.load_schedule!
41
+ assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
42
+
43
+ # we allow multiple rails_env definition, it should work also:
44
+ Resque.schedule = {:some_ivar_job => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp", 'rails_env' => 'staging, production'}}
45
+ Resque::Scheduler.load_schedule!
46
+ assert_equal(2, Resque::Scheduler.rufus_scheduler.all_jobs.size)
47
+ end
48
+
49
+ def test_enqueue_from_config_dont_puts_stuff_in_the_resque_queue_when_env_doesnt_match
50
+ # RAILS_ENV is not set:
51
+ assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
52
+ Resque.schedule = {:some_ivar_job => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp", 'rails_env' => 'staging'}}
53
+ Resque::Scheduler.load_schedule!
54
+ assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
55
+
56
+ # SET RAILS_ENV to a common value:
57
+ ENV['RAILS_ENV'] = 'production'
58
+ Resque.schedule = {:some_ivar_job => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp", 'rails_env' => 'staging'}}
59
+ Resque::Scheduler.load_schedule!
60
+ assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
61
+ end
62
+
63
+ def test_enqueue_from_config_when_rails_env_arg_is_not_set
64
+ # The job should be loaded, since a missing rails_env means ALL envs.
65
+ ENV['RAILS_ENV'] = 'production'
66
+ assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
67
+ Resque.schedule = {:some_ivar_job => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp"}}
68
+ Resque::Scheduler.load_schedule!
69
+ assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
70
+ end
71
+
72
+ def test_config_makes_it_into_the_rufus_scheduler
73
+ assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
74
+
75
+ Resque.schedule = {:some_ivar_job => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp"}}
76
+ Resque::Scheduler.load_schedule!
77
+
78
+ assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
79
+ end
80
+
81
+ def test_can_reload_schedule
82
+ Resque.schedule = {:some_ivar_job => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp"}}
83
+ Resque::Scheduler.load_schedule!
84
+
85
+ assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
86
+
87
+ Resque::Scheduler.reload_schedule!
88
+
89
+ assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
90
+
91
+ assert_equal '/tmp/2', Resque.schedule[:some_ivar_job2]["args"]
92
+ end
93
+
94
+ def test_adheres_to_lint
95
+ assert_nothing_raised do
96
+ Resque::Plugin.lint(Resque::Scheduler)
97
+ end
98
+ end
99
+
100
+ end
@@ -0,0 +1,78 @@
1
+
2
+ # Pretty much copied this file from the resque test_helper since we want
3
+ # to do all the same stuff
4
+
5
+ dir = File.dirname(File.expand_path(__FILE__))
6
+
7
+ require 'rubygems'
8
+ require 'test/unit'
9
+ require 'mocha'
10
+ require 'resque'
11
+ require File.join(dir, '../lib/resque_scheduler')
12
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__)) + '/../lib'
13
+
14
+
15
+ #
16
+ # make sure we can run redis
17
+ #
18
+
19
+ if !system("which redis-server")
20
+ puts '', "** can't find `redis-server` in your path"
21
+ puts "** try running `sudo rake install`"
22
+ abort ''
23
+ end
24
+
25
+
26
+ #
27
+ # start our own redis when the tests start,
28
+ # kill it when they end
29
+ #
30
+
31
+ at_exit do
32
+ next if $!
33
+
34
+ if defined?(MiniTest)
35
+ exit_code = MiniTest::Unit.new.run(ARGV)
36
+ else
37
+ exit_code = Test::Unit::AutoRunner.run
38
+ end
39
+
40
+ pid = `ps -e -o pid,command | grep [r]edis-test`.split(" ")[0]
41
+ puts "Killing test redis server..."
42
+ `rm -f #{dir}/dump.rdb`
43
+ Process.kill("KILL", pid.to_i)
44
+ exit exit_code
45
+ end
46
+
47
+ puts "Starting redis for testing at localhost:9736..."
48
+ `redis-server #{dir}/redis-test.conf`
49
+ Resque.redis = 'localhost:9736'
50
+
51
+ ##
52
+ # test/spec/mini 3
53
+ # http://gist.github.com/25455
54
+ # chris@ozmm.org
55
+ #
56
+ def context(*args, &block)
57
+ return super unless (name = args.first) && block
58
+ require 'test/unit'
59
+ klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
60
+ def self.test(name, &block)
61
+ define_method("test_#{name.gsub(/\W/,'_')}", &block) if block
62
+ end
63
+ def self.xtest(*args) end
64
+ def self.setup(&block) define_method(:setup, &block) end
65
+ def self.teardown(&block) define_method(:teardown, &block) end
66
+ end
67
+ (class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') }
68
+ klass.class_eval &block
69
+ end
70
+
71
+ class SomeJob
72
+ def self.perform(repo_id, path)
73
+ end
74
+ end
75
+
76
+ class SomeIvarJob < SomeJob
77
+ @queue = :ivar
78
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brianjlandau-resque-scheduler
3
+ version: !ruby/object:Gem::Version
4
+ hash: 63
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 10
9
+ - 0
10
+ version: 1.10.0
11
+ platform: ruby
12
+ authors:
13
+ - Ben VandenBos
14
+ - Brian Landau
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-10-18 00:00:00 -04:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: redis
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 13
31
+ segments:
32
+ - 2
33
+ - 0
34
+ - 1
35
+ version: 2.0.1
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: resque
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 55
47
+ segments:
48
+ - 1
49
+ - 8
50
+ - 0
51
+ version: 1.8.0
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: rufus-scheduler
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ type: :runtime
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: jeweler
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ type: :development
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ name: mocha
84
+ prerelease: false
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ type: :development
95
+ version_requirements: *id005
96
+ - !ruby/object:Gem::Dependency
97
+ name: rack-test
98
+ prerelease: false
99
+ requirement: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ type: :development
109
+ version_requirements: *id006
110
+ description: |-
111
+ Light weight job scheduling on top of Resque.
112
+ Adds methods enqueue_at/enqueue_in to schedule jobs in the future.
113
+ Also supports queueing jobs on a fixed, cron-like schedule.
114
+ email: brianjlandau@gmail.com
115
+ executables: []
116
+
117
+ extensions: []
118
+
119
+ extra_rdoc_files:
120
+ - LICENSE
121
+ - README.markdown
122
+ files:
123
+ - .gitignore
124
+ - HISTORY.md
125
+ - LICENSE
126
+ - README.markdown
127
+ - Rakefile
128
+ - lib/resque/scheduler.rb
129
+ - lib/resque_scheduler.rb
130
+ - lib/resque_scheduler/server.rb
131
+ - lib/resque_scheduler/server/views/delayed.erb
132
+ - lib/resque_scheduler/server/views/delayed_timestamp.erb
133
+ - lib/resque_scheduler/server/views/scheduler.erb
134
+ - lib/resque_scheduler/tasks.rb
135
+ - lib/resque_scheduler/version.rb
136
+ - resque-scheduler.gemspec
137
+ - tasks/resque_scheduler.rake
138
+ - test/delayed_queue_test.rb
139
+ - test/redis-test.conf
140
+ - test/resque-web_test.rb
141
+ - test/scheduler_test.rb
142
+ - test/test_helper.rb
143
+ has_rdoc: true
144
+ homepage: http://github.com/brianjlandau/resque-scheduler
145
+ licenses: []
146
+
147
+ post_install_message:
148
+ rdoc_options:
149
+ - --charset=UTF-8
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 3
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ hash: 3
167
+ segments:
168
+ - 0
169
+ version: "0"
170
+ requirements: []
171
+
172
+ rubyforge_project:
173
+ rubygems_version: 1.3.7
174
+ signing_key:
175
+ specification_version: 3
176
+ summary: Light weight job scheduling on top of Resque
177
+ test_files:
178
+ - test/delayed_queue_test.rb
179
+ - test/resque-web_test.rb
180
+ - test/scheduler_test.rb
181
+ - test/test_helper.rb