resque-scheduler 4.2.1 → 4.3.0

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.

Potentially problematic release.


This version of resque-scheduler might be problematic. Click here for more details.

Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CODE_OF_CONDUCT.md +74 -0
  3. data/HISTORY.md +7 -0
  4. data/README.md +7 -6
  5. data/{bin → exe}/resque-scheduler +0 -0
  6. data/lib/resque/scheduler/env.rb +5 -1
  7. data/lib/resque/scheduler/version.rb +1 -1
  8. data/resque-scheduler.gemspec +21 -7
  9. metadata +12 -53
  10. data/.gitignore +0 -17
  11. data/.rubocop.yml +0 -18
  12. data/.rubocop_todo.yml +0 -71
  13. data/.simplecov +0 -3
  14. data/.travis.yml +0 -26
  15. data/.vagrant-provision-as-vagrant.sh +0 -15
  16. data/.vagrant-provision.sh +0 -23
  17. data/.vagrant-skel/bash_profile +0 -7
  18. data/.vagrant-skel/bashrc +0 -7
  19. data/Vagrantfile +0 -14
  20. data/examples/Rakefile +0 -2
  21. data/examples/config/initializers/resque-web.rb +0 -37
  22. data/examples/dynamic-scheduling/README.md +0 -28
  23. data/examples/dynamic-scheduling/app/jobs/fix_schedules_job.rb +0 -52
  24. data/examples/dynamic-scheduling/app/jobs/send_email_job.rb +0 -9
  25. data/examples/dynamic-scheduling/app/models/user.rb +0 -16
  26. data/examples/dynamic-scheduling/config/resque.yml +0 -4
  27. data/examples/dynamic-scheduling/config/static_schedule.yml +0 -7
  28. data/examples/dynamic-scheduling/lib/tasks/resque.rake +0 -48
  29. data/examples/run-resque-web +0 -3
  30. data/script/migrate_to_timestamps_set.rb +0 -16
  31. data/tasks/resque_scheduler.rake +0 -2
  32. data/test/cli_test.rb +0 -231
  33. data/test/delayed_queue_test.rb +0 -925
  34. data/test/env_test.rb +0 -47
  35. data/test/multi_process_test.rb +0 -125
  36. data/test/resque-web_test.rb +0 -364
  37. data/test/scheduler_args_test.rb +0 -222
  38. data/test/scheduler_hooks_test.rb +0 -55
  39. data/test/scheduler_locking_test.rb +0 -316
  40. data/test/scheduler_setup_test.rb +0 -141
  41. data/test/scheduler_task_test.rb +0 -72
  42. data/test/scheduler_test.rb +0 -473
  43. data/test/test_helper.rb +0 -147
  44. data/test/util_test.rb +0 -17
@@ -1,15 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -e
4
- set -x
5
-
6
- ln -svf /vagrant/.vagrant-skel/bashrc ~/.bashrc
7
- ln -svf /vagrant/.vagrant-skel/bash_profile ~/.bash_profile
8
-
9
- source ~/.bashrc
10
-
11
- set +x
12
- curl -L https://get.rvm.io | bash -s stable --ruby=2.0.0 --auto-dotfiles
13
-
14
- source ~/.rvm/scripts/rvm
15
- gem install --no-ri --no-rdoc bundler foreman
@@ -1,23 +0,0 @@
1
- #!/bin/bash
2
-
3
- export DEBIAN_FRONTEND=noninteractive
4
-
5
- umask 022
6
-
7
- set -e
8
- set -x
9
-
10
- apt-get update -yq
11
- apt-get install --no-install-suggests -yq python-software-properties
12
- add-apt-repository -y ppa:chris-lea/redis-server
13
- apt-get update -yq
14
- apt-get install --no-install-suggests -yq \
15
- build-essential \
16
- byobu \
17
- curl \
18
- git \
19
- make \
20
- redis-server \
21
- screen
22
-
23
- su - vagrant -c /vagrant/.vagrant-provision-as-vagrant.sh
@@ -1,7 +0,0 @@
1
- #!bash
2
-
3
- [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
4
-
5
- if [[ "$PS1" ]] ; then
6
- cd /vagrant
7
- fi
@@ -1,7 +0,0 @@
1
- #!bash
2
-
3
- export LANG='en_US.UTF-8'
4
- export LANGUAGE='en_US.UTF-8'
5
- export LC_ALL='en_US.UTF-8'
6
-
7
- export PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
@@ -1,14 +0,0 @@
1
- # vim:filetype=ruby
2
-
3
- Vagrant.configure('2') do |config|
4
- config.vm.hostname = 'resque-scheduler'
5
- config.vm.box = 'precise64'
6
- config.vm.box_url = 'http://cloud-images.ubuntu.com/vagrant/precise/' <<
7
- 'current/precise-server-cloudimg-amd64-vagrant-disk1.box'
8
-
9
- config.vm.network :private_network, ip: '33.33.33.10', auto_correct: true
10
- config.vm.network :forwarded_port, guest: 5678, host: 15678,
11
- auto_correct: true
12
-
13
- config.vm.provision :shell, path: '.vagrant-provision.sh'
14
- end
@@ -1,2 +0,0 @@
1
- # vim:fileencoding=utf-8
2
- require 'resque/scheduler/tasks'
@@ -1,37 +0,0 @@
1
- # vim:fileencoding=utf-8
2
-
3
- require 'json'
4
- require 'yaml'
5
- require 'resque'
6
-
7
- redis_env_var = ENV['REDIS_PROVIDER'] || 'REDIS_URL'
8
- Resque.redis = ENV[redis_env_var] || 'localhost:6379'
9
-
10
- require 'resque-scheduler'
11
- require 'resque/scheduler/server'
12
-
13
- schedule_yml = ENV['RESQUE_SCHEDULE_YML']
14
- if schedule_yml
15
- Resque.schedule = if File.exist?(schedule_yml)
16
- YAML.load_file(schedule_yml)
17
- else
18
- YAML.load(schedule_yml)
19
- end
20
- end
21
-
22
- schedule_json = ENV['RESQUE_SCHEDULE_JSON']
23
- if schedule_json
24
- Resque.schedule = if File.exist?(schedule_json)
25
- JSON.parse(File.read(schedule_json))
26
- else
27
- JSON.parse(schedule_json)
28
- end
29
- end
30
-
31
- class Putter
32
- @queue = 'putting'
33
-
34
- def self.perform(*args)
35
- args.each { |arg| puts arg }
36
- end
37
- end
@@ -1,28 +0,0 @@
1
- Dynamic Scheduling Example
2
- ==========================
3
-
4
- Possible workaround for
5
- https://github.com/resque/resque-scheduler/issues/269
6
-
7
- This folder contains just the relevant files you would have to put into
8
- a rails application.
9
-
10
- The problem we want to fix is that when resque-scheduler is restarted,
11
- any dynamically added jobs are wiped. To fix it, we will run a
12
- statically scheduled job that dynamically reschedules any missing
13
- dynamic schedules.
14
-
15
- This workaround uses both a dynamic schedule (every time a user is
16
- created, a schedule is dynamically added to send him a daily email) and
17
- a static schedule (a job runs hourly, starting 10 seconds after starting
18
- resque-scheduler, to check that there is a scheduled job to send an
19
- email for every user; missing schedules are added).
20
-
21
- This way even though a resque-scheduler restart wipes all dynamic
22
- schedules, they are recreated by the `fix_schedules` job that runs in
23
- the static schedule. Even if dynamic schedules were lost for any reason
24
- (data loss in redis clusters, whatever), they will be recreated hourly.
25
-
26
- This workaround requires that enough information is saved in the
27
- database to recreate all dynamic schedules. In this case we create one
28
- dynamically scheduled job for every user in the database.
@@ -1,52 +0,0 @@
1
- # vim:fileencoding=utf-8
2
- #
3
- # Background job to fix the schedule for email sending. Any missing
4
- # schedule will be added to resque-schedule.
5
- #
6
- # Recent resque-scheduler versions wipe all dynamic schedules when
7
- # restarting. This means all dynamic schedules, which are added via the
8
- # API, are wiped on each application redeployment. A workaround for this
9
- # sometimes undesirable behavior is to make this job part of a static
10
- # schedule (see config/initializers/resque.rb and
11
- # config/static_schedule.yml). This job will be scheduled to run every
12
- # hour even after restarting resque-schedule, and will add back the
13
- # dynamic schedules that were wiped on restart. It also serves as
14
- # safeguard against schedules getting lost for any reason.
15
- #
16
- # For more detail about this unfortunate behavior of resque-scheduler see:
17
- #
18
- # https://github.com/resque/resque-scheduler/issues/269
19
- #
20
- # The perform method of this class will be invoked from a Resque worker.
21
-
22
- class FixSchedulesJob
23
- @queue = :send_emails
24
-
25
- # Fix email sending schedules. Any user which does not have scheduled
26
- # sending of emails will be detected, and the missing scheduled job
27
- # will be added to resque-schedule.
28
- #
29
- # This method is intended to be invoked from Resque, which means it is
30
- # performed in the background.
31
- def self.perform
32
- users_unscheduled = []
33
-
34
- User.all.each do |user|
35
- # get schedule for the user
36
- schedule = Resque.fetch_schedule("send_email_#{user.id}")
37
- # if a user has no schedule, add it to the array
38
- users_unscheduled << user if schedule.nil?
39
- end
40
-
41
- unless users_unscheduled.empty?
42
- users_unscheduled.each do |user|
43
- name = "send_email_#{user.id}"
44
- config = {}
45
- config[:class] = 'SendEmailJob'
46
- config[:args] = user.id
47
- config[:every] = '1d'
48
- Resque.set_schedule(name, config)
49
- end
50
- end
51
- end
52
- end
@@ -1,9 +0,0 @@
1
- # vim:fileencoding=utf-8
2
-
3
- class SendEmailJob
4
- @queue = :send_emails
5
-
6
- def self.perform(_user_id)
7
- # ... do whatever you have to do to send an email to the user
8
- end
9
- end
@@ -1,16 +0,0 @@
1
- # vim:fileencoding=utf-8
2
-
3
- class User < ActiveRecord::Base
4
- after_create :schedule_send_email
5
-
6
- private
7
-
8
- def schedule_send_email
9
- name = "send_email_#{id}"
10
- config = {}
11
- config[:class] = 'SendEmailJob'
12
- config[:args] = id
13
- config[:every] = '1d'
14
- Resque.set_schedule(name, config)
15
- end
16
- end
@@ -1,4 +0,0 @@
1
- ---
2
- development: localhost:6379
3
- test: localhost:6379:1
4
- production: localhost:6379 # or wherever your redis-server is in production
@@ -1,7 +0,0 @@
1
- ---
2
- FixSchedulesJob:
3
- description: 'Add any missing email sending schedules'
4
- queue: send_emails
5
- every:
6
- - '1h'
7
- - :first_in: '10s'
@@ -1,48 +0,0 @@
1
- # vim:fileencoding=utf-8
2
-
3
- require 'resque/tasks'
4
- require 'resque/scheduler/tasks'
5
- require 'yaml'
6
-
7
- namespace :resque do
8
- task :setup do
9
- require 'resque'
10
- require 'resque-scheduler'
11
-
12
- rails_root = ENV['RAILS_ROOT'] || File.expand_path('../../../', __FILE__)
13
- rails_env = ENV['RAILS_ENV'] || 'development'
14
-
15
- # In resque-only servers we must require each job class individually,
16
- # because we're not running the full Rails app
17
- require "#{rails_root}/app/jobs/send_email_job"
18
- require "#{rails_root}/app/jobs/fix_schedules_job"
19
-
20
- resque_config = YAML.load_file(
21
- File.join(rails_root.to_s, 'config', 'resque.yml')
22
- )
23
- Resque.redis = resque_config[rails_env]
24
-
25
- # If you want to be able to dynamically change the schedule,
26
- # uncomment this line. A dynamic schedule can be updated via the
27
- # Resque::Scheduler.set_schedule (and remove_schedule) methods.
28
- # When dynamic is set to true, the scheduler process looks for
29
- # schedule changes and applies them on the fly.
30
- # Note: This feature is only available in >=2.0.0.
31
- Resque::Scheduler.dynamic = true
32
-
33
- # Load static schedule (only in background servers).
34
- # The schedule doesn't need to be stored in a YAML, it just needs to
35
- # be a hash. YAML is usually the easiest.
36
- Resque.schedule = YAML.load_file(
37
- File.join(rails_root.to_s, 'config', 'static_schedule.yml')
38
- )
39
-
40
- Resque.before_fork do |job|
41
- # Reconnect to the DB before running each job. Otherwise we get errors if
42
- # the DB is restarted after starting Resque.
43
- # Absolutely necessary on Heroku, otherwise we get a "PG::Error: SSL
44
- # SYSCALL error: EOF detected" exception
45
- ActiveRecord::Base.establish_connection
46
- end
47
- end
48
- end
@@ -1,3 +0,0 @@
1
- #!/bin/bash
2
- cd "$(dirname $0)"
3
- exec resque-web --foreground --no-launch config/initializers/resque-web.rb
@@ -1,16 +0,0 @@
1
- # vim:fileencoding=utf-8
2
-
3
- require 'redis'
4
- require 'resque'
5
-
6
- if ARGV.size != 1
7
- puts 'migrate_to_timestamps_set.rb <redis-host:redis-port>'
8
- exit
9
- end
10
-
11
- Resque.redis = ARGV[0]
12
- redis = Resque.redis
13
- Array(redis.keys('delayed:*')).each do |key|
14
- jobs = redis.lrange(key, 0, -1)
15
- jobs.each { |job| redis.sadd("timestamps:#{job}", key) }
16
- end
@@ -1,2 +0,0 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
- require 'resque/scheduler/tasks'
@@ -1,231 +0,0 @@
1
- # vim:fileencoding=utf-8
2
- require_relative 'test_helper'
3
-
4
- context 'Cli' do
5
- def mock_runtime_env
6
- mock.tap { |m| m.stubs(:setup) }
7
- end
8
-
9
- def new_cli(argv = [], env = {})
10
- Resque::Scheduler::Cli.new(argv, env).tap do |cli|
11
- cli.stubs(:runtime_env).returns(mock_runtime_env)
12
- end
13
- end
14
-
15
- test 'does not require any positional arguments' do
16
- assert(!new_cli.nil?)
17
- end
18
-
19
- test 'initializes verbose from the env' do
20
- cli = new_cli([], 'VERBOSE' => 'foo')
21
- assert_equal('foo', cli.send(:options)[:verbose])
22
- end
23
-
24
- test 'defaults to non-verbose' do
25
- assert_equal(false, !!new_cli.send(:options)[:verbose])
26
- end
27
-
28
- test 'accepts verbose via -v' do
29
- cli = new_cli(%w(-v))
30
- cli.parse_options
31
- assert_equal(true, cli.send(:options)[:verbose])
32
- end
33
-
34
- test 'accepts verbose via --verbose' do
35
- cli = new_cli(%w(--verbose))
36
- cli.parse_options
37
- assert_equal(true, cli.send(:options)[:verbose])
38
- end
39
-
40
- test 'initializes background from the env' do
41
- cli = new_cli([], 'BACKGROUND' => '1')
42
- assert_equal('1', cli.send(:options)[:background])
43
- end
44
-
45
- test 'defaults to background=false' do
46
- assert_equal(false, !!new_cli.send(:options)[:background])
47
- end
48
-
49
- test 'accepts background via -B' do
50
- cli = new_cli(%w(-B))
51
- cli.parse_options
52
- assert_equal(true, cli.send(:options)[:background])
53
- end
54
-
55
- test 'accepts background via --background' do
56
- cli = new_cli(%w(--background))
57
- cli.parse_options
58
- assert_equal(true, cli.send(:options)[:background])
59
- end
60
-
61
- test 'initializes pidfile from the env' do
62
- cli = new_cli([], 'PIDFILE' => 'bar')
63
- assert_equal('bar', cli.send(:options)[:pidfile])
64
- end
65
-
66
- test 'defaults to nil pidfile' do
67
- assert_equal(nil, new_cli.send(:options)[:pidfile])
68
- end
69
-
70
- test 'accepts pidfile via -P' do
71
- cli = new_cli(%w(-P foo))
72
- cli.parse_options
73
- assert_equal('foo', cli.send(:options)[:pidfile])
74
- end
75
-
76
- test 'accepts pidfile via --pidfile' do
77
- cli = new_cli(%w(--pidfile foo))
78
- cli.parse_options
79
- assert_equal('foo', cli.send(:options)[:pidfile])
80
- end
81
-
82
- test 'defaults to nil dynamic' do
83
- assert_equal(nil, new_cli.send(:options)[:dynamic])
84
- end
85
-
86
- test 'initializes env from the env' do
87
- cli = new_cli([], 'RAILS_ENV' => 'flurb')
88
- assert_equal('flurb', cli.send(:options)[:env])
89
- end
90
-
91
- test 'defaults to nil env' do
92
- assert_equal(nil, new_cli.send(:options)[:env])
93
- end
94
-
95
- test 'accepts env via -E' do
96
- cli = new_cli(%w(-E bork))
97
- cli.parse_options
98
- assert_equal('bork', cli.send(:options)[:env])
99
- end
100
-
101
- test 'accepts env via --environment' do
102
- cli = new_cli(%w(--environment hork))
103
- cli.parse_options
104
- assert_equal('hork', cli.send(:options)[:env])
105
- end
106
-
107
- test 'initializes initializer_path from the env' do
108
- cli = new_cli([], 'INITIALIZER_PATH' => 'herp.rb')
109
- assert_equal('herp.rb', cli.send(:options)[:initializer_path])
110
- end
111
-
112
- test 'defaults to nil initializer_path' do
113
- assert_equal(nil, new_cli.send(:options)[:initializer_path])
114
- end
115
-
116
- test 'accepts initializer_path via -I' do
117
- cli = new_cli(%w(-I hambone.rb))
118
- cli.parse_options
119
- assert_equal('hambone.rb', cli.send(:options)[:initializer_path])
120
- end
121
-
122
- test 'accepts initializer_path via --initalizer-path' do
123
- cli = new_cli(%w(--initializer-path cookies.rb))
124
- cli.parse_options
125
- assert_equal('cookies.rb', cli.send(:options)[:initializer_path])
126
- end
127
-
128
- test 'loads given initilalizer_path' do
129
- cli = new_cli(%w(--initializer-path fuzzbert.rb))
130
- cli.expects(:load).with('fuzzbert.rb')
131
- cli.pre_run
132
- end
133
-
134
- test 'initializes quiet from the env' do
135
- cli = new_cli([], 'QUIET' => '1')
136
- assert_equal('1', cli.send(:options)[:quiet])
137
- end
138
-
139
- test 'defaults to un-quieted' do
140
- assert_equal(false, !!new_cli.send(:options)[:quiet])
141
- end
142
-
143
- test 'accepts quiet via -q' do
144
- cli = new_cli(%w(-q))
145
- cli.parse_options
146
- assert_equal(true, cli.send(:options)[:quiet])
147
- end
148
-
149
- test 'accepts quiet via --quiet' do
150
- cli = new_cli(%w(--quiet))
151
- cli.parse_options
152
- assert_equal(true, cli.send(:options)[:quiet])
153
- end
154
-
155
- test 'initializes logfile from the env' do
156
- cli = new_cli([], 'LOGFILE' => 'example.log')
157
- assert_equal('example.log', cli.send(:options)[:logfile])
158
- end
159
-
160
- test 'defaults to nil logfile' do
161
- assert_equal(nil, new_cli.send(:options)[:logfile])
162
- end
163
-
164
- test 'accepts logfile via -l' do
165
- cli = new_cli(%w(-l hurm.out))
166
- cli.parse_options
167
- assert_equal('hurm.out', cli.send(:options)[:logfile])
168
- end
169
-
170
- test 'accepts logfile via --logfile' do
171
- cli = new_cli(%w(--logfile flam.log))
172
- cli.parse_options
173
- assert_equal('flam.log', cli.send(:options)[:logfile])
174
- end
175
-
176
- test 'initializes logformat from the env' do
177
- cli = new_cli([], 'LOGFORMAT' => 'fancy')
178
- assert_equal('fancy', cli.send(:options)[:logformat])
179
- end
180
-
181
- test 'defaults to nil logformat' do
182
- assert_equal(nil, new_cli.send(:options)[:logformat])
183
- end
184
-
185
- test 'accepts logformat via -F' do
186
- cli = new_cli(%w(-F silly))
187
- cli.parse_options
188
- assert_equal('silly', cli.send(:options)[:logformat])
189
- end
190
-
191
- test 'accepts logformat via --logformat' do
192
- cli = new_cli(%w(--logformat flimsy))
193
- cli.parse_options
194
- assert_equal('flimsy', cli.send(:options)[:logformat])
195
- end
196
-
197
- test 'defaults to dynamic=false' do
198
- assert_equal(false, !!new_cli.send(:options)[:dynamic])
199
- end
200
-
201
- test 'initializes app_name from the env' do
202
- cli = new_cli([], 'APP_NAME' => 'sprocket')
203
- assert_equal('sprocket', cli.send(:options)[:app_name])
204
- end
205
-
206
- test 'defaults to nil app_name' do
207
- assert_equal(nil, new_cli.send(:options)[:app_name])
208
- end
209
-
210
- test 'accepts app_name via -n' do
211
- cli = new_cli(%w(-n hambone))
212
- cli.parse_options
213
- assert_equal('hambone', cli.send(:options)[:app_name])
214
- end
215
-
216
- test 'accepts app_name via --app-name' do
217
- cli = new_cli(%w(--app-name flimsy))
218
- cli.parse_options
219
- assert_equal('flimsy', cli.send(:options)[:app_name])
220
- end
221
-
222
- test 'runs Resque::Scheduler' do
223
- Resque::Scheduler.expects(:run)
224
- Resque::Scheduler::Cli.run!([], {})
225
- end
226
-
227
- test 'does not create keys for unspecified environment variables' do
228
- cli = new_cli([], 'DYNAMIC_SCHEDULE' => 'true')
229
- assert_equal({ dynamic: 'true' }, cli.send(:options))
230
- end
231
- end