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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52ec65c4ec0ca66d57f30457b6bf0327f43ee479
4
- data.tar.gz: c311cfb9241e8145f324386833366b764cc73c1a
3
+ metadata.gz: 1a6855db526a23fa48933504b568fded11df2722
4
+ data.tar.gz: c28537792117c9937fb5deb5c18f287ebf90596f
5
5
  SHA512:
6
- metadata.gz: 2d9b317975e2914d4ba8f3a6fd12981fccd9341d8432bd9508d6cdadf322f786fb0bb9cda5dd5015c9b053300ab3f1f5dc00ae88b568de9f22296dc416e1542a
7
- data.tar.gz: 670ec7558441a32ede722f66c1821ee524498ee595fc9c03f230f1b313b9bdd3dabb58a7f8d883726a735b9007c4783635fdcad222b7234d8c6799e32b30a794
6
+ metadata.gz: 5abd5f9a6d32b08f7f92c274d355daaddebf32d9e93ec9197982c044c6a9928fc15a79a3412fa6c6589f98356d0183c768d20c6b8ad3cbbabd56bf256c2fa35c
7
+ data.tar.gz: 8abb91541f341a7e620ba2c602370e384b3093a0e6c4a7fd87ab0d6510c4610dc5be7dee8cdb562140320074805f3f1a0ff7c6d05969ca1ffe4c305087e60f09
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
1
  --color
2
- --warnings
3
2
  --require spec_helper
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - "2.3.0"
5
+
6
+ sudo: false
7
+
8
+ cache: bundler
9
+
10
+ script: bundle exec rake
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).
@@ -28,4 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "rspec"
29
29
  spec.add_development_dependency "sqlite3"
30
30
  spec.add_development_dependency "delayed_job_active_record"
31
+ spec.add_development_dependency "activejob"
32
+
31
33
  end
@@ -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,16 @@
1
+ module DelayedCronJob
2
+ module ActiveJob
3
+ module Enqueuing
4
+
5
+ def self.included(klass)
6
+ klass.send(:attr_accessor, :cron)
7
+ end
8
+
9
+ def enqueue(options = {})
10
+ self.cron = options[:cron] if options[:cron]
11
+ super
12
+ end
13
+
14
+ end
15
+ end
16
+ 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
@@ -1,3 +1,3 @@
1
1
  module DelayedCronJob
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  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
@@ -1,4 +1,4 @@
1
-
1
+ require 'spec_helper'
2
2
 
3
3
  describe DelayedCronJob do
4
4
 
@@ -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.6.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-01-11 00:00:00.000000000 Z
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