activejob-scheduler 0.0.1 → 1.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +12 -15
- data/.rspec +1 -0
- data/.rubocop.yml +17 -0
- data/.travis.yml +26 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +13 -1
- data/LICENSE.txt +17 -18
- data/MIT-LICENSE +20 -0
- data/README.md +133 -44
- data/Rakefile +27 -4
- data/activejob-scheduler.gemspec +29 -19
- data/bin/console +14 -0
- data/bin/rails +12 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/setup +7 -0
- data/bin/test +5 -0
- data/lib/active_job/scheduler.rb +33 -2
- data/lib/active_job/scheduler/engine.rb +17 -0
- data/lib/active_job/scheduler/error.rb +9 -0
- data/lib/active_job/scheduler/event.rb +89 -0
- data/lib/active_job/scheduler/interval.rb +46 -0
- data/lib/active_job/scheduler/job.rb +84 -53
- data/lib/active_job/scheduler/mailer.rb +35 -0
- data/lib/active_job/scheduler/missing_config_error.rb +12 -0
- data/lib/active_job/scheduler/not_defined_error.rb +12 -0
- data/lib/active_job/scheduler/not_supported_error.rb +12 -0
- data/lib/active_job/scheduler/schedule.rb +114 -0
- data/lib/active_job/scheduler/version.rb +4 -1
- data/lib/activejob-scheduler.rb +3 -0
- data/lib/tasks/activejob_scheduler_tasks.rake +8 -0
- metadata +196 -53
- data/bin/ajs +0 -7
- data/lib/active_job/scheduler/cli.rb +0 -113
- data/lib/active_job/scheduler/jobs.rb +0 -32
- data/lib/active_job/scheduler/task.rb +0 -38
- data/spec/active_job/scheduler/job_spec.rb +0 -44
- data/spec/active_job/scheduler/jobs_spec.rb +0 -24
- data/spec/fixtures/jobs.yml +0 -3
- data/spec/spec_helper.rb +0 -4
data/bin/ajs
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
|
3
|
-
module ActiveJob::Scheduler
|
4
|
-
# Controller for the schedule via the CLI.
|
5
|
-
class Cli
|
6
|
-
attr_reader :env, :options
|
7
|
-
|
8
|
-
# A short doc explaining the CLI.
|
9
|
-
USAGE = <<-EOF.gsub(/ {6}/, '')
|
10
|
-
Usage: activejob-scheduler [options]
|
11
|
-
|
12
|
-
Runs an active_job scheduler process directly (rather than via rake).
|
13
|
-
|
14
|
-
EOF
|
15
|
-
|
16
|
-
# The various options our CLI takes.
|
17
|
-
OPTIONS = [
|
18
|
-
{
|
19
|
-
args: ['-n', '--app-name [APP_NAME]',
|
20
|
-
'Application name for procline'],
|
21
|
-
callback: ->(options) { ->(n) { options[:app_name] = n } }
|
22
|
-
},
|
23
|
-
{
|
24
|
-
args: ['-B', '--background', 'Run in the background [BACKGROUND]'],
|
25
|
-
callback: ->(options) { ->(b) { options[:background] = b } }
|
26
|
-
},
|
27
|
-
{
|
28
|
-
args: ['-D', '--dynamic-schedule',
|
29
|
-
'Enable dynamic scheduling [DYNAMIC_SCHEDULE]'],
|
30
|
-
callback: ->(options) { ->(d) { options[:dynamic] = d } }
|
31
|
-
},
|
32
|
-
{
|
33
|
-
args: ['-E', '--environment [RAILS_ENV]', 'Environment name'],
|
34
|
-
callback: ->(options) { ->(e) { options[:env] = e } }
|
35
|
-
},
|
36
|
-
{
|
37
|
-
args: ['-I', '--initializer-path [INITIALIZER_PATH]',
|
38
|
-
'Path to optional initializer ruby file'],
|
39
|
-
callback: ->(options) { ->(i) { options[:initializer_path] = i } }
|
40
|
-
},
|
41
|
-
{
|
42
|
-
args: ['-i', '--interval [RESQUE_SCHEDULER_INTERVAL]',
|
43
|
-
'Interval for checking if a scheduled job must run'],
|
44
|
-
callback: ->(options) { ->(i) { options[:poll_sleep_amount] = i } }
|
45
|
-
},
|
46
|
-
{
|
47
|
-
args: ['-l', '--logfile [LOGFILE]', 'Log file name'],
|
48
|
-
callback: ->(options) { ->(l) { options[:logfile] = l } }
|
49
|
-
},
|
50
|
-
{
|
51
|
-
args: ['-F', '--logformat [LOGFORMAT]', 'Log output format'],
|
52
|
-
callback: ->(options) { ->(f) { options[:logformat] = f } }
|
53
|
-
},
|
54
|
-
{
|
55
|
-
args: ['-P', '--pidfile [PIDFILE]', 'PID file name'],
|
56
|
-
callback: ->(options) { ->(p) { options[:pidfile] = p } }
|
57
|
-
},
|
58
|
-
{
|
59
|
-
args: ['-q', '--quiet', 'Run with minimal output [QUIET]'],
|
60
|
-
callback: ->(options) { ->(q) { options[:quiet] = q } }
|
61
|
-
},
|
62
|
-
{
|
63
|
-
args: ['-v', '--verbose', 'Run with verbose output [VERBOSE]'],
|
64
|
-
callback: ->(options) { ->(v) { options[:verbose] = v } }
|
65
|
-
}
|
66
|
-
].freeze
|
67
|
-
|
68
|
-
# Instantiate a new CLI handler with the given args.
|
69
|
-
def initialize(argv, env)
|
70
|
-
@env = env
|
71
|
-
@args = argv
|
72
|
-
@options = option_parser.parse! argv
|
73
|
-
end
|
74
|
-
|
75
|
-
# Start the scheduler CLI immediately from given command-line
|
76
|
-
# arguments.
|
77
|
-
def self.run(argv, env)
|
78
|
-
new(argv, env).run
|
79
|
-
end
|
80
|
-
|
81
|
-
# Now that we have args, actually begin running the schedule by
|
82
|
-
# loading each Job into Rufus::Scheduler. Rufus uses methods like
|
83
|
-
# `every` and `cron` to determine what kind of job you're pushing
|
84
|
-
# into it, so we use send() to give the Job object the power to make
|
85
|
-
# that choice.
|
86
|
-
def run
|
87
|
-
jobs.each do |job|
|
88
|
-
rufus.send job.interval, *job.rufus_params
|
89
|
-
end
|
90
|
-
|
91
|
-
rufus.start
|
92
|
-
end
|
93
|
-
|
94
|
-
private
|
95
|
-
def option_parser
|
96
|
-
OptionParser.new do |parser|
|
97
|
-
parser.banner = USAGE
|
98
|
-
|
99
|
-
OPTIONS.each do |opt|
|
100
|
-
parser.on(*opt[:args], &(opt[:callback].call(options)))
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def jobs
|
106
|
-
@jobs ||= Jobs.from_yaml
|
107
|
-
end
|
108
|
-
|
109
|
-
def rufus
|
110
|
-
@rufus ||= Rufus::Scheduler.new
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module ActiveJob::Scheduler
|
4
|
-
class Jobs
|
5
|
-
include Enumerable
|
6
|
-
|
7
|
-
attr_reader :path
|
8
|
-
|
9
|
-
def initialize(from_path)
|
10
|
-
@path = from_path
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.from_yaml
|
14
|
-
new "config/jobs.yml"
|
15
|
-
end
|
16
|
-
|
17
|
-
def each
|
18
|
-
collection.each { |job| yield job }
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
def collection
|
23
|
-
params.keys.map do |name|
|
24
|
-
Job.new params[name].merge name: name
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def params
|
29
|
-
@collection ||= YAML::load_file path
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'active_job/scheduler/cli'
|
2
|
-
require 'rake/tasklib'
|
3
|
-
|
4
|
-
module ActiveJob::Scheduler
|
5
|
-
# Run the scheduler as a Rake task, and preload the Rails environment.
|
6
|
-
#
|
7
|
-
# Example Task:
|
8
|
-
#
|
9
|
-
# ActiveJob::Scheduler::Task.new :schedule
|
10
|
-
#
|
11
|
-
# Example Shell Command:
|
12
|
-
#
|
13
|
-
# rake schedule
|
14
|
-
#
|
15
|
-
# The task can also be pre-loaded with a task called `schedule:setup`.
|
16
|
-
class Task < Rake::TaskLib
|
17
|
-
attr_reader :name
|
18
|
-
|
19
|
-
def initialize(with_name=:schedule)
|
20
|
-
@name = with_name
|
21
|
-
yield self if block_given?
|
22
|
-
define
|
23
|
-
end
|
24
|
-
|
25
|
-
def define
|
26
|
-
namespace name do
|
27
|
-
task :setup
|
28
|
-
|
29
|
-
task :run do
|
30
|
-
ActiveJob::Scheduler::Cli.run ARGV, ENV
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
desc "Run the ActiveJob::Scheduler"
|
35
|
-
task name => ["#{name}:setup", "#{name}:run"]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'active_job/scheduler/job'
|
3
|
-
|
4
|
-
class Worker
|
5
|
-
def perform(record)
|
6
|
-
# do nothing
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
module ActiveJob::Scheduler
|
11
|
-
describe Job do
|
12
|
-
subject do
|
13
|
-
Job.new \
|
14
|
-
name: 'testing',
|
15
|
-
every: '30s',
|
16
|
-
job_class: 'Worker'
|
17
|
-
end
|
18
|
-
|
19
|
-
before do
|
20
|
-
allow(subject.send(:jobject)).to receive(:enqueue).and_return true
|
21
|
-
end
|
22
|
-
|
23
|
-
it "finds the interval" do
|
24
|
-
expect(subject.interval).to eq(:every)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "finds the interval value" do
|
28
|
-
expect(subject.interval_value).to eq('30s')
|
29
|
-
end
|
30
|
-
|
31
|
-
it "finds the job class name" do
|
32
|
-
expect(subject.job_class).to eq('Worker')
|
33
|
-
end
|
34
|
-
|
35
|
-
it "it finds the description or gets one set" do
|
36
|
-
expect(subject.description).to eq('Testing')
|
37
|
-
end
|
38
|
-
|
39
|
-
it "enqueues the job with active_job" do
|
40
|
-
expect(subject).to be_valid
|
41
|
-
expect(subject.enqueue).to be_true
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'active_job/scheduler/jobs'
|
3
|
-
|
4
|
-
module ActiveJob::Scheduler
|
5
|
-
describe Jobs do
|
6
|
-
let :fixture_config do
|
7
|
-
File.expand_path('../../../fixtures/jobs.yml', __FILE__)
|
8
|
-
end
|
9
|
-
|
10
|
-
subject { Jobs.new fixture_config }
|
11
|
-
|
12
|
-
it "reads from a yaml file on disk" do
|
13
|
-
expect(subject.path).to eq(fixture_config)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "defines jobs from each params stanza it sees" do
|
17
|
-
expect(subject.send(:collection).first).to be_a Job
|
18
|
-
end
|
19
|
-
|
20
|
-
it "iterates over the collection as an enumerable" do
|
21
|
-
expect(subject).to respond_to :each
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/spec/fixtures/jobs.yml
DELETED
data/spec/spec_helper.rb
DELETED