active_scheduler 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/.rspec +2 -0
- data/.travis.yml +18 -0
- data/Gemfile +9 -0
- data/Guardfile +12 -0
- data/LICENSE +20 -0
- data/README.markdown +48 -0
- data/Rakefile +14 -0
- data/active_scheduler.gemspec +27 -0
- data/lib/active_scheduler.rb +8 -0
- data/lib/active_scheduler/resque_wrapper.rb +38 -0
- data/lib/active_scheduler/version.rb +3 -0
- data/spec/active_scheduler/resque_wrapper_spec.rb +91 -0
- data/spec/fixtures/cron_job.yaml +7 -0
- data/spec/fixtures/no_queue.yaml +6 -0
- data/spec/fixtures/simple_job.json +8 -0
- data/spec/fixtures/simple_job.yaml +7 -0
- data/spec/fixtures/two_jobs.yaml +10 -0
- data/spec/spec_helper.rb +11 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 24a57f88cef6610e4ad50c31ed383bca44c9b28e
|
4
|
+
data.tar.gz: 3070e1622de6dcae251394146347d7bbdae4d956
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f3d4a07c0d161179ca17eba8e40102da2fdc86c920b96ada6a414c94341143898b55f1519cbcb85e4cf8aed7b65c05d60077cc612cf485ce05f2f2af67a180b1
|
7
|
+
data.tar.gz: 98b7ea984dcf84a5c44f3a1de4c1c3c1923c1b7977cbdf253d99cb5cd200b1432a1a4b1225b4dbb19a579acaaed3e795a607ef760b530080b9ba056bcc84a53b
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Gem related stuff
|
2
|
+
*.gem
|
3
|
+
/pkg
|
4
|
+
/.bundle
|
5
|
+
/Gemfile.lock
|
6
|
+
/vendor
|
7
|
+
|
8
|
+
# Testing stuff
|
9
|
+
/coverage
|
10
|
+
/spec/reports
|
11
|
+
*.log
|
12
|
+
|
13
|
+
# RBX stuff
|
14
|
+
/.rbx/
|
15
|
+
|
16
|
+
# Editor temp/backup files
|
17
|
+
*~
|
18
|
+
.*.sw?
|
19
|
+
|
20
|
+
# General
|
21
|
+
/nbproject
|
22
|
+
.DS_Store
|
23
|
+
/.rvmrc
|
24
|
+
/.yardoc
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.0
|
6
|
+
- 2.1.5
|
7
|
+
- 2.2.0
|
8
|
+
matrix:
|
9
|
+
allow_failures:
|
10
|
+
- rvm: 1.9.3
|
11
|
+
env:
|
12
|
+
- "RAILS_VERSION=4.2.0"
|
13
|
+
notifications:
|
14
|
+
email:
|
15
|
+
recipients:
|
16
|
+
- 60tonangel@gmail.com
|
17
|
+
on_success: change
|
18
|
+
on_failure: change
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
guard :rspec, all_after_pass: false, all_on_start: false, failed_mode: :none, cmd: 'NO_COVERALLS=true rspec --color --no-profile --format progress' do
|
2
|
+
|
3
|
+
# Run all tests if these change:
|
4
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
5
|
+
watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
|
6
|
+
|
7
|
+
# Any spec runs itself:
|
8
|
+
watch(%r{^spec/.+_spec\.rb$})
|
9
|
+
|
10
|
+
# lib/foo.rb runs spec/foo.rb...
|
11
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
12
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Justin Aiken
|
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.markdown
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
[![Gem Version](http://img.shields.io/gem/v/active_scheduler.svg)](https://rubygems.org/gems/active_scheduler)[![Build Status](http://img.shields.io/travis/JustinAiken/active_scheduler/master.svg)](http://travis-ci.org/JustinAiken/active_scheduler) [![Coveralls branch](http://img.shields.io/coveralls/JustinAiken/active_scheduler/master.svg)](https://coveralls.io/r/JustinAiken/active_scheduler?branch=master)[![Code Climate](http://img.shields.io/codeclimate/github/JustinAiken/active_scheduler.svg)](https://codeclimate.com/github/JustinAiken/active_scheduler)
|
2
|
+
|
3
|
+
# active_scheduler
|
4
|
+
|
5
|
+
active_scheduler is a gem to take a standard schedule one would use with [resque scheduler](https://github.com/resque/resque-scheduler) and wraps it to work with [ActiveJob](https://github.com/rails/rails/tree/master/activejob).
|
6
|
+
|
7
|
+
Currently only Resque is supported, but pull requests to add other queues (sidekiq, etc) would be welcomed!
|
8
|
+
|
9
|
+
## Requirements/Support
|
10
|
+
|
11
|
+
- Rails
|
12
|
+
- ActiveJob 4.2+
|
13
|
+
- ActiveSupport 4.2+
|
14
|
+
- Resque
|
15
|
+
- Resque Scheduler
|
16
|
+
|
17
|
+
## Setup
|
18
|
+
|
19
|
+
#### Installation
|
20
|
+
|
21
|
+
Add `active_scheduler` to your Gemfile.
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
In your Resque initializer:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'resque/server'
|
29
|
+
require 'resque/scheduler/server'
|
30
|
+
require 'active_scheduler'
|
31
|
+
|
32
|
+
# ... Set up your Resque ...
|
33
|
+
...
|
34
|
+
|
35
|
+
yaml_schedule = YAML.load_file("#{Rails.root}/config/resque_schedule.yaml") || {}
|
36
|
+
wrapped_schedule = ActiveScheduler::ResqueWrapper.wrap yaml_schedule
|
37
|
+
Resque.schedule = wrapped_schedule
|
38
|
+
```
|
39
|
+
|
40
|
+
## Credits
|
41
|
+
|
42
|
+
- Written by [@JustinAiken](https://www.github.com/JustinAiken)
|
43
|
+
- Wrapper class idea by [@ryanwjackson](https://www.github.com/ryanwjackson)
|
44
|
+
- Special thanks to [Rocketmade](http://www.rocketmade.com/) for development resources.
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
MIT
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Run tests "
|
12
|
+
task :default do
|
13
|
+
Rake::Task["spec"].invoke
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "active_scheduler/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.platform = Gem::Platform::RUBY
|
6
|
+
s.name = "active_scheduler"
|
7
|
+
s.version = ActiveScheduler::VERSION
|
8
|
+
s.authors = ["Justin Aiken"]
|
9
|
+
s.email = ["jaiken@rocketmade.com"]
|
10
|
+
s.license = 'MIT'
|
11
|
+
s.homepage = "https://github.com/JustinAiken/active_scheduler"
|
12
|
+
s.summary = %q{Scheduling for ActiveJob}
|
13
|
+
s.description = %q{A wrapper for scheduling jobs through ActiveJob}
|
14
|
+
|
15
|
+
s.rubyforge_project = "active_scheduler"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency 'activejob', '>= 4.2.0'
|
22
|
+
s.add_dependency 'activesupport', '>= 4.2.0'
|
23
|
+
|
24
|
+
s.add_development_dependency 'rspec-rails', '~> 3.1'
|
25
|
+
s.add_development_dependency 'guard-rspec', '~> 4.2'
|
26
|
+
s.add_development_dependency 'coveralls'
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ActiveScheduler
|
2
|
+
class ResqueWrapper
|
3
|
+
|
4
|
+
def self.perform(job_data)
|
5
|
+
klass = Object.const_get job_data['job_class']
|
6
|
+
|
7
|
+
if job_data.has_key? 'arguments'
|
8
|
+
klass.perform_later *job_data['arguments']
|
9
|
+
else
|
10
|
+
klass.perform_later
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.wrap(schedule)
|
15
|
+
schedule = HashWithIndifferentAccess.new(schedule)
|
16
|
+
|
17
|
+
schedule.each do |job, opts|
|
18
|
+
next if opts[:class] =~ /ActiveScheduler::ResqueWrapper/
|
19
|
+
|
20
|
+
queue = opts[:queue] || 'default'
|
21
|
+
|
22
|
+
schedule[job] = {
|
23
|
+
class: 'ActiveScheduler::ResqueWrapper',
|
24
|
+
queue: queue,
|
25
|
+
args: [{
|
26
|
+
job_class: opts[:class],
|
27
|
+
queue_name: queue,
|
28
|
+
arguments: opts[:arguments]
|
29
|
+
}]
|
30
|
+
}
|
31
|
+
|
32
|
+
schedule[job][:description] = opts.fetch(:description, nil) if opts.fetch(:description, nil)
|
33
|
+
schedule[job][:every] = opts.fetch(:every, nil) if opts.fetch(:every, nil)
|
34
|
+
schedule[job][:cron] = opts.fetch(:cron, nil) if opts.fetch(:cron, nil)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
describe ActiveScheduler::ResqueWrapper do
|
5
|
+
describe ".wrap" do
|
6
|
+
let(:wrapped) { described_class.wrap schedule }
|
7
|
+
|
8
|
+
context "with a simple job yaml" do
|
9
|
+
let(:schedule) { YAML.load_file 'spec/fixtures/simple_job.yaml' }
|
10
|
+
|
11
|
+
it "queues up a simple job" do
|
12
|
+
expect(wrapped['simple_job']).to eq(
|
13
|
+
"class" => "ActiveScheduler::ResqueWrapper",
|
14
|
+
"queue" => "simple",
|
15
|
+
"description" => "It's a simple job.",
|
16
|
+
"every" => "30s",
|
17
|
+
"args" => [{
|
18
|
+
"job_class" => "SimpleJob",
|
19
|
+
"queue_name" => "simple",
|
20
|
+
"arguments" => nil
|
21
|
+
}]
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "with a simple job json" do
|
27
|
+
let(:schedule) { YAML.load_file 'spec/fixtures/simple_job.json' }
|
28
|
+
|
29
|
+
it "queues up a simple job" do
|
30
|
+
expect(wrapped['simple_job']).to eq(
|
31
|
+
"class" => "ActiveScheduler::ResqueWrapper",
|
32
|
+
"queue" => "simple",
|
33
|
+
"description" => "It's a simple job.",
|
34
|
+
"every" => "30s",
|
35
|
+
"args" => [{
|
36
|
+
"job_class" => "SimpleJob",
|
37
|
+
"queue_name" => "simple",
|
38
|
+
"arguments" => nil
|
39
|
+
}]
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with a multiple jobs in the schedule" do
|
45
|
+
let(:schedule) { YAML.load_file 'spec/fixtures/two_jobs.yaml' }
|
46
|
+
|
47
|
+
it "queues them all up simple job" do
|
48
|
+
expect(wrapped['job_1']['args'][0]['job_class']).to eq 'JobOne'
|
49
|
+
expect(wrapped['job_2']['args'][0]['job_class']).to eq 'JobTwo'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with a cron instead of an every" do
|
54
|
+
let(:schedule) { YAML.load_file 'spec/fixtures/cron_job.yaml' }
|
55
|
+
|
56
|
+
it "uses that instead" do
|
57
|
+
expect(wrapped['cron_job']['cron']).to eq '* * * *'
|
58
|
+
expect(wrapped['cron_job']['every']).to be_nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when the queue is blank" do
|
63
|
+
let(:schedule) { YAML.load_file 'spec/fixtures/no_queue.yaml' }
|
64
|
+
|
65
|
+
it "uses 'default'" do
|
66
|
+
expect(wrapped['no_queue_job']['queue']).to eq 'default'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe ".perform" do
|
72
|
+
class TestKlass
|
73
|
+
end
|
74
|
+
|
75
|
+
let(:job_data) { {'job_class' => 'TestKlass'} }
|
76
|
+
|
77
|
+
after { described_class.perform job_data }
|
78
|
+
|
79
|
+
it "gets the true job class and ActiveJob's it up" do
|
80
|
+
expect(TestKlass).to receive :perform_later
|
81
|
+
end
|
82
|
+
|
83
|
+
context "with arguments" do
|
84
|
+
let(:job_data) { {'job_class' => 'TestKlass', 'arguments' => [1, 2]} }
|
85
|
+
|
86
|
+
it "passes the arguments" do
|
87
|
+
expect(TestKlass).to receive(:perform_later).with 1, 2
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_scheduler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Aiken
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activejob
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: coveralls
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: A wrapper for scheduling jobs through ActiveJob
|
84
|
+
email:
|
85
|
+
- jaiken@rocketmade.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- Guardfile
|
95
|
+
- LICENSE
|
96
|
+
- README.markdown
|
97
|
+
- Rakefile
|
98
|
+
- active_scheduler.gemspec
|
99
|
+
- lib/active_scheduler.rb
|
100
|
+
- lib/active_scheduler/resque_wrapper.rb
|
101
|
+
- lib/active_scheduler/version.rb
|
102
|
+
- spec/active_scheduler/resque_wrapper_spec.rb
|
103
|
+
- spec/fixtures/cron_job.yaml
|
104
|
+
- spec/fixtures/no_queue.yaml
|
105
|
+
- spec/fixtures/simple_job.json
|
106
|
+
- spec/fixtures/simple_job.yaml
|
107
|
+
- spec/fixtures/two_jobs.yaml
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
homepage: https://github.com/JustinAiken/active_scheduler
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project: active_scheduler
|
129
|
+
rubygems_version: 2.4.5
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Scheduling for ActiveJob
|
133
|
+
test_files: []
|