resque-scheduler 2.2.0 → 4.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/dependabot.yml +12 -0
- data/.github/funding.yml +4 -0
- data/.github/workflows/codeql-analysis.yml +59 -0
- data/.github/workflows/rubocop.yml +27 -0
- data/.github/workflows/ruby.yml +81 -0
- data/AUTHORS.md +31 -0
- data/CHANGELOG.md +539 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +26 -2
- data/LICENSE +1 -1
- data/README.md +423 -91
- data/Rakefile +12 -35
- data/exe/resque-scheduler +5 -0
- data/lib/resque/scheduler/cli.rb +147 -0
- data/lib/resque/scheduler/configuration.rb +102 -0
- data/lib/resque/scheduler/delaying_extensions.rb +371 -0
- data/lib/resque/scheduler/env.rb +85 -0
- data/lib/resque/scheduler/extension.rb +13 -0
- data/lib/resque/scheduler/failure_handler.rb +11 -0
- data/lib/resque/scheduler/lock/base.rb +12 -3
- data/lib/resque/scheduler/lock/basic.rb +4 -5
- data/lib/resque/scheduler/lock/resilient.rb +52 -43
- data/lib/resque/scheduler/lock.rb +2 -1
- data/lib/resque/scheduler/locking.rb +104 -0
- data/lib/resque/scheduler/logger_builder.rb +83 -0
- data/lib/resque/scheduler/plugin.rb +31 -0
- data/lib/resque/scheduler/scheduling_extensions.rb +142 -0
- data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed.erb +23 -8
- data/lib/resque/scheduler/server/views/delayed_schedules.erb +20 -0
- data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed_timestamp.erb +1 -1
- data/lib/resque/scheduler/server/views/scheduler.erb +58 -0
- data/lib/resque/scheduler/server/views/search.erb +69 -0
- data/lib/resque/scheduler/server/views/search_form.erb +4 -0
- data/lib/resque/scheduler/server.rb +268 -0
- data/lib/resque/scheduler/signal_handling.rb +40 -0
- data/lib/resque/scheduler/tasks.rb +25 -0
- data/lib/resque/scheduler/util.rb +39 -0
- data/lib/resque/scheduler/version.rb +7 -0
- data/lib/resque/scheduler.rb +333 -149
- data/lib/resque-scheduler.rb +4 -0
- data/resque-scheduler.gemspec +56 -20
- metadata +205 -104
- data/.gitignore +0 -8
- data/.rubocop.yml +0 -120
- data/.travis.yml +0 -10
- data/HISTORY.md +0 -180
- data/lib/resque/scheduler_locking.rb +0 -90
- data/lib/resque_scheduler/logger_builder.rb +0 -51
- data/lib/resque_scheduler/plugin.rb +0 -25
- data/lib/resque_scheduler/server/views/scheduler.erb +0 -44
- data/lib/resque_scheduler/server.rb +0 -92
- data/lib/resque_scheduler/tasks.rb +0 -40
- data/lib/resque_scheduler/version.rb +0 -3
- data/lib/resque_scheduler.rb +0 -355
- data/script/migrate_to_timestamps_set.rb +0 -14
- data/tasks/resque_scheduler.rake +0 -2
- data/test/delayed_queue_test.rb +0 -383
- data/test/redis-test.conf +0 -108
- data/test/resque-web_test.rb +0 -116
- data/test/scheduler_args_test.rb +0 -156
- data/test/scheduler_hooks_test.rb +0 -23
- data/test/scheduler_locking_test.rb +0 -180
- data/test/scheduler_setup_test.rb +0 -59
- data/test/scheduler_test.rb +0 -256
- data/test/support/redis_instance.rb +0 -129
- data/test/test_helper.rb +0 -92
- /data/lib/{resque_scheduler → resque/scheduler}/server/views/requeue-params.erb +0 -0
@@ -1,129 +0,0 @@
|
|
1
|
-
require 'socket'
|
2
|
-
require 'timeout'
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
class RedisInstance
|
6
|
-
class << self
|
7
|
-
@running = false
|
8
|
-
@port = nil
|
9
|
-
@pid = nil
|
10
|
-
|
11
|
-
def run_if_needed!
|
12
|
-
run! unless running?
|
13
|
-
end
|
14
|
-
|
15
|
-
def run!
|
16
|
-
ensure_pid_directory
|
17
|
-
reassign_redis_clients
|
18
|
-
start_redis_server
|
19
|
-
|
20
|
-
if $?.success?
|
21
|
-
wait_for_pid
|
22
|
-
puts "Booted isolated Redis on port #{port} with PID #{pid}."
|
23
|
-
|
24
|
-
wait_for_redis_boot
|
25
|
-
|
26
|
-
# Ensure we tear down Redis on Ctrl+C / test failure.
|
27
|
-
at_exit do
|
28
|
-
RedisInstance.stop!
|
29
|
-
end
|
30
|
-
else
|
31
|
-
raise "Failed to start Redis on port #{port}."
|
32
|
-
end
|
33
|
-
|
34
|
-
@running = true
|
35
|
-
end
|
36
|
-
|
37
|
-
def stop!
|
38
|
-
$stdout.puts "Sending TERM to Redis (#{pid})..."
|
39
|
-
Process.kill('TERM', pid)
|
40
|
-
|
41
|
-
@port = nil
|
42
|
-
@running = false
|
43
|
-
@pid = nil
|
44
|
-
end
|
45
|
-
|
46
|
-
def running?
|
47
|
-
@running
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def wait_for_redis_boot
|
53
|
-
Timeout::timeout(10) do
|
54
|
-
begin
|
55
|
-
while Resque.redis.ping != 'PONG'
|
56
|
-
end
|
57
|
-
rescue
|
58
|
-
# silence all errors
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def ensure_pid_directory
|
64
|
-
FileUtils.mkdir_p(File.dirname(pid_file))
|
65
|
-
end
|
66
|
-
|
67
|
-
def reassign_redis_clients
|
68
|
-
Resque.redis = Redis.new(:hostname => '127.0.0.1', :port => port, :thread_safe => true)
|
69
|
-
end
|
70
|
-
|
71
|
-
def start_redis_server
|
72
|
-
IO.popen("redis-server -", "w+") do |server|
|
73
|
-
server.write(config)
|
74
|
-
server.close_write
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def pid
|
79
|
-
@pid ||= File.read(pid_file).to_i
|
80
|
-
end
|
81
|
-
|
82
|
-
def wait_for_pid
|
83
|
-
Timeout::timeout(10) do
|
84
|
-
while !File.exist?(pid_file)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def port
|
90
|
-
@port ||= random_port
|
91
|
-
end
|
92
|
-
|
93
|
-
def pid_file
|
94
|
-
"/tmp/redis-scheduler-test.pid"
|
95
|
-
end
|
96
|
-
|
97
|
-
def config
|
98
|
-
<<-EOF
|
99
|
-
daemonize yes
|
100
|
-
pidfile #{pid_file}
|
101
|
-
port #{port}
|
102
|
-
EOF
|
103
|
-
end
|
104
|
-
|
105
|
-
# Returns a random port in the upper (10000-65535) range.
|
106
|
-
def random_port
|
107
|
-
ports = (10000..65535).to_a
|
108
|
-
|
109
|
-
loop do
|
110
|
-
port = ports[rand(ports.size)]
|
111
|
-
return port if port_available?('127.0.0.1', port)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def port_available?(ip, port, seconds=1)
|
116
|
-
Timeout::timeout(seconds) do
|
117
|
-
begin
|
118
|
-
TCPSocket.new(ip, port).close
|
119
|
-
false
|
120
|
-
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
121
|
-
true
|
122
|
-
end
|
123
|
-
end
|
124
|
-
rescue Timeout::Error
|
125
|
-
true
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
data/test/test_helper.rb
DELETED
@@ -1,92 +0,0 @@
|
|
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/setup'
|
10
|
-
require 'resque'
|
11
|
-
$LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__)) + '/../lib'
|
12
|
-
require 'resque_scheduler'
|
13
|
-
require 'resque_scheduler/server'
|
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
|
-
# Start our own Redis when the tests start. RedisInstance will take care of
|
27
|
-
# starting and stopping.
|
28
|
-
require File.dirname(__FILE__) + '/support/redis_instance'
|
29
|
-
RedisInstance.run!
|
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
|
-
exit exit_code
|
41
|
-
end
|
42
|
-
|
43
|
-
##
|
44
|
-
# test/spec/mini 3
|
45
|
-
# http://gist.github.com/25455
|
46
|
-
# chris@ozmm.org
|
47
|
-
#
|
48
|
-
def context(*args, &block)
|
49
|
-
return super unless (name = args.first) && block
|
50
|
-
require 'test/unit'
|
51
|
-
klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
|
52
|
-
def self.test(name, &block)
|
53
|
-
define_method("test_#{name.gsub(/\W/,'_')}", &block) if block
|
54
|
-
end
|
55
|
-
def self.xtest(*args) end
|
56
|
-
def self.setup(&block) define_method(:setup, &block) end
|
57
|
-
def self.teardown(&block) define_method(:teardown, &block) end
|
58
|
-
end
|
59
|
-
(class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') }
|
60
|
-
klass.class_eval(&block)
|
61
|
-
end
|
62
|
-
|
63
|
-
class FakeCustomJobClass
|
64
|
-
def self.scheduled(queue, klass, *args); end
|
65
|
-
end
|
66
|
-
|
67
|
-
class FakeCustomJobClassEnqueueAt
|
68
|
-
@queue = :test
|
69
|
-
def self.scheduled(queue, klass, *args); end
|
70
|
-
end
|
71
|
-
|
72
|
-
class SomeJob
|
73
|
-
def self.perform(repo_id, path)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
class SomeIvarJob < SomeJob
|
78
|
-
@queue = :ivar
|
79
|
-
end
|
80
|
-
|
81
|
-
class SomeRealClass
|
82
|
-
def self.queue
|
83
|
-
:some_real_queue
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def nullify_logger
|
88
|
-
Resque::Scheduler.mute = nil
|
89
|
-
Resque::Scheduler.verbose = nil
|
90
|
-
Resque::Scheduler.logfile = nil
|
91
|
-
Resque::Scheduler.logger = nil
|
92
|
-
end
|
File without changes
|