delayed_cron_job 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/.travis.yml +10 -0
- data/README.md +4 -0
- data/delayed_cron_job.gemspec +2 -0
- data/lib/delayed_cron_job.rb +13 -0
- data/lib/delayed_cron_job/active_job/enqueuing.rb +16 -0
- data/lib/delayed_cron_job/active_job/queue_adapter.rb +33 -0
- data/lib/delayed_cron_job/version.rb +1 -1
- data/spec/active_job_spec.rb +69 -0
- data/spec/delayed_cron_job_spec.rb +1 -1
- data/spec/spec_helper.rb +4 -1
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a6855db526a23fa48933504b568fded11df2722
|
4
|
+
data.tar.gz: c28537792117c9937fb5deb5c18f287ebf90596f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5abd5f9a6d32b08f7f92c274d355daaddebf32d9e93ec9197982c044c6a9928fc15a79a3412fa6c6589f98356d0183c768d20c6b8ad3cbbabd56bf256c2fa35c
|
7
|
+
data.tar.gz: 8abb91541f341a7e620ba2c602370e384b3093a0e6c4a7fd87ab0d6510c4610dc5be7dee8cdb562140320074805f3f1a0ff7c6d05969ca1ffe4c305087e60f09
|
data/.rspec
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -28,6 +28,10 @@ When enqueuing a job, simply pass the `cron` option, e.g.:
|
|
28
28
|
|
29
29
|
Delayed::Job.enqueue(MyRepeatedJob.new, cron: '15 */6 * * 1-5')
|
30
30
|
|
31
|
+
Or, when using Active Job:
|
32
|
+
|
33
|
+
MyJob.set(cron: '*/5 * * * *').perform_later
|
34
|
+
|
31
35
|
Any crontab compatible cron expressions are supported (see `man 5 crontab`).
|
32
36
|
The credits for the `Cronline` class used go to
|
33
37
|
[rufus-scheduler](https://github.com/jmettraux/rufus-scheduler).
|
data/delayed_cron_job.gemspec
CHANGED
data/lib/delayed_cron_job.rb
CHANGED
@@ -18,3 +18,16 @@ if defined?(Delayed::Backend::ActiveRecord) && Delayed::Backend::ActiveRecord::J
|
|
18
18
|
end
|
19
19
|
|
20
20
|
Delayed::Worker.plugins << DelayedCronJob::Plugin
|
21
|
+
|
22
|
+
if defined?(::ActiveJob)
|
23
|
+
require 'delayed_cron_job/active_job/enqueuing'
|
24
|
+
require 'delayed_cron_job/active_job/queue_adapter'
|
25
|
+
|
26
|
+
ActiveJob::Base.send(:include, DelayedCronJob::ActiveJob::Enqueuing)
|
27
|
+
if ActiveJob::QueueAdapters::DelayedJobAdapter.respond_to?(:enqueue)
|
28
|
+
ActiveJob::QueueAdapters::DelayedJobAdapter.extend(DelayedCronJob::ActiveJob::QueueAdapter)
|
29
|
+
else
|
30
|
+
ActiveJob::QueueAdapters::DelayedJobAdapter.send(:include, DelayedCronJob::ActiveJob::QueueAdapter)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module DelayedCronJob
|
2
|
+
module ActiveJob
|
3
|
+
module QueueAdapter
|
4
|
+
|
5
|
+
def self.included(klass)
|
6
|
+
klass.send(:alias_method, :enqueue, :enqueue_with_cron)
|
7
|
+
klass.send(:alias_method, :enqueue_at, :enqueue_at_with_cron)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.extended(klass)
|
11
|
+
meta = class << klass; self; end
|
12
|
+
meta.send(:alias_method, :enqueue, :enqueue_with_cron)
|
13
|
+
meta.send(:alias_method, :enqueue_at, :enqueue_at_with_cron)
|
14
|
+
end
|
15
|
+
|
16
|
+
def enqueue_with_cron(job)
|
17
|
+
enqueue_at(job, nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
def enqueue_at_with_cron(job, timestamp)
|
21
|
+
options = { queue: job.queue_name,
|
22
|
+
cron: job.cron }
|
23
|
+
options[:run_at] = Time.at(timestamp) if timestamp
|
24
|
+
options[:priority] = job.priority if job.respond_to?(:priority)
|
25
|
+
wrapper = ::ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper.new(job.serialize)
|
26
|
+
delayed_job = Delayed::Job.enqueue(wrapper, options)
|
27
|
+
job.provider_job_id = delayed_job.id if job.respond_to?(:provider_job_id=)
|
28
|
+
delayed_job
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveJob do
|
4
|
+
|
5
|
+
class CronJob < ActiveJob::Base
|
6
|
+
class_attribute :cron
|
7
|
+
|
8
|
+
def perform; end
|
9
|
+
|
10
|
+
def cron
|
11
|
+
@cron ||= self.class.cron
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
before { Delayed::Job.delete_all }
|
16
|
+
|
17
|
+
let(:cron) { '5 1 * * *' }
|
18
|
+
let(:job) { CronJob.set(cron: cron).perform_later }
|
19
|
+
let(:delayed_job) { Delayed::Job.first }
|
20
|
+
let(:worker) { Delayed::Worker.new }
|
21
|
+
let(:now) { Delayed::Job.db_time_now }
|
22
|
+
let(:next_run) do
|
23
|
+
run = now.hour * 60 + now.min >= 65 ? now + 1.day : now
|
24
|
+
Time.utc(run.year, run.month, run.day, 1, 5)
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with cron' do
|
28
|
+
it 'sets run_at on enqueue' do
|
29
|
+
expect { job }.to change { Delayed::Job.count }.by(1)
|
30
|
+
expect(delayed_job.run_at).to eq(next_run)
|
31
|
+
expect(delayed_job.cron).to eq(cron)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'schedules a new job after success' do
|
35
|
+
job
|
36
|
+
delayed_job.update_column(:run_at, now)
|
37
|
+
delayed_job.reload
|
38
|
+
|
39
|
+
worker.work_off
|
40
|
+
|
41
|
+
expect(Delayed::Job.count).to eq(1)
|
42
|
+
j = Delayed::Job.first
|
43
|
+
expect(j.id).to eq(delayed_job.id)
|
44
|
+
expect(j.cron).to eq(delayed_job.cron)
|
45
|
+
expect(j.run_at).to eq(next_run)
|
46
|
+
expect(j.attempts).to eq(1)
|
47
|
+
expect(j.last_error).to eq(nil)
|
48
|
+
expect(j.created_at).to eq(delayed_job.created_at)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'without cron' do
|
53
|
+
let(:job) { CronJob.perform_later }
|
54
|
+
|
55
|
+
it 'sets run_at but not cron on enqueue' do
|
56
|
+
CronJob.cron = nil
|
57
|
+
expect { job }.to change { Delayed::Job.count }.by(1)
|
58
|
+
expect(delayed_job.run_at).to be <= now
|
59
|
+
expect(delayed_job.cron).to be_nil
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'uses default cron on enqueue' do
|
63
|
+
CronJob.cron = cron
|
64
|
+
expect { job }.to change { Delayed::Job.count }.by(1)
|
65
|
+
expect(delayed_job.run_at).to eq(next_run)
|
66
|
+
expect(delayed_job.cron).to eq(cron)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -15,11 +15,14 @@
|
|
15
15
|
#
|
16
16
|
|
17
17
|
require 'delayed_job_active_record'
|
18
|
+
require 'active_job'
|
18
19
|
require 'delayed_cron_job'
|
19
20
|
|
20
21
|
Delayed::Worker.logger = Logger.new('/tmp/dj.log')
|
21
22
|
ENV['RAILS_ENV'] = 'test'
|
22
23
|
|
24
|
+
ActiveJob::Base.queue_adapter = :delayed_job
|
25
|
+
|
23
26
|
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
|
24
27
|
ActiveRecord::Base.logger = Delayed::Worker.logger
|
25
28
|
ActiveRecord::Migration.verbose = false
|
@@ -45,5 +48,5 @@ end
|
|
45
48
|
|
46
49
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
47
50
|
RSpec.configure do |config|
|
48
|
-
|
51
|
+
|
49
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delayed_cron_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pascal Zumkehr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: delayed_job
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activejob
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: |-
|
98
112
|
Delayed Cron Job is an extension to Delayed::Job
|
99
113
|
that allows you to set cron expressions for your
|
@@ -106,17 +120,21 @@ extra_rdoc_files: []
|
|
106
120
|
files:
|
107
121
|
- ".gitignore"
|
108
122
|
- ".rspec"
|
123
|
+
- ".travis.yml"
|
109
124
|
- Gemfile
|
110
125
|
- LICENSE.txt
|
111
126
|
- README.md
|
112
127
|
- Rakefile
|
113
128
|
- delayed_cron_job.gemspec
|
114
129
|
- lib/delayed_cron_job.rb
|
130
|
+
- lib/delayed_cron_job/active_job/enqueuing.rb
|
131
|
+
- lib/delayed_cron_job/active_job/queue_adapter.rb
|
115
132
|
- lib/delayed_cron_job/cronline.rb
|
116
133
|
- lib/delayed_cron_job/plugin.rb
|
117
134
|
- lib/delayed_cron_job/version.rb
|
118
135
|
- lib/generators/delayed_job/cron_generator.rb
|
119
136
|
- lib/generators/delayed_job/templates/cron_migration.rb
|
137
|
+
- spec/active_job_spec.rb
|
120
138
|
- spec/delayed_cron_job_spec.rb
|
121
139
|
- spec/spec_helper.rb
|
122
140
|
homepage: https://github.com/codez/delayed_cron_job
|
@@ -145,5 +163,6 @@ specification_version: 4
|
|
145
163
|
summary: An extension to Delayed::Job that allows you to set cron expressions for
|
146
164
|
your jobs to run regularly.
|
147
165
|
test_files:
|
166
|
+
- spec/active_job_spec.rb
|
148
167
|
- spec/delayed_cron_job_spec.rb
|
149
168
|
- spec/spec_helper.rb
|