recurring_active_job 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/.rspec +0 -0
- data/.travis.yml +0 -0
- data/Gemfile +0 -0
- data/LICENSE +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +153 -153
- data/Rakefile +0 -0
- data/bin/console +0 -0
- data/bin/setup +0 -0
- data/config/database.yml +0 -0
- data/config/migrate/20180627123939_create_recurring_active_job.rb +0 -0
- data/config/schema.rb +29 -29
- data/lib/recurring_active_job/base.rb +84 -80
- data/lib/recurring_active_job/model.rb +0 -0
- data/lib/recurring_active_job/version.rb +3 -3
- data/lib/recurring_active_job.rb +0 -0
- data/recurring_active_job.gemspec +41 -41
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db5fcab0fb358e480791ac6e5edc3022a7eea74389a721aa01d6db3bf762839a
|
4
|
+
data.tar.gz: c7bf5cb3943b2d18cd42a80820a1a65936b4b70dd8a017def66e63a5c5bba4bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe5f736bec2bc1d283a3d8da25768afffb5cc6686096e3b6a28b92c4044393966851e13b01a2b8e18a1931ab036b7a26c204dad14360489c2781416276231f90
|
7
|
+
data.tar.gz: 49ccafa5e1d73a3ce27f63975549baa1b7a7f3a44ae7ec37dfcc93510f5e72f4d07cbecc23d6c2bc172c941720380909d7eb4dfd3b58b750d673a464afc9d490
|
data/.gitignore
CHANGED
File without changes
|
data/.rspec
CHANGED
File without changes
|
data/.travis.yml
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -1,153 +1,153 @@
|
|
1
|
-
# RecurringActiveJob
|
2
|
-
|
3
|
-
#### Adapter agnostic ActiveJob scheduler based on time spent between executions.
|
4
|
-
|
5
|
-
<!--- Version informartion -->
|
6
|
-
*You are viewing the README of version [v0.
|
7
|
-
<!--- Version informartion end -->
|
8
|
-
|
9
|
-
| Branch | Status |
|
10
|
-
| ------ | ------ |
|
11
|
-
| Release | [![Build Status](https://travis-ci.org/thisismydesign/recurring_active_job.svg?branch=release)](https://travis-ci.org/thisismydesign/recurring_active_job) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/recurring_active_job/badge.svg?branch=release)](https://coveralls.io/github/thisismydesign/recurring_active_job?branch=release) [![Gem Version](https://badge.fury.io/rb/recurring_active_job.svg)](https://badge.fury.io/rb/recurring_active_job) [![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/recurring_active_job?type=total)](https://rubygems.org/gems/recurring_active_job) |
|
12
|
-
| Development | [![Build Status](https://travis-ci.org/thisismydesign/recurring_active_job.svg?branch=master)](https://travis-ci.org/thisismydesign/recurring_active_job) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/recurring_active_job/badge.svg?branch=master)](https://coveralls.io/github/thisismydesign/recurring_active_job?branch=master) |
|
13
|
-
|
14
|
-
Regular scheduler 10 minute setting:
|
15
|
-
- Runs every 10 minutes
|
16
|
-
- Run#1 00:10-00:11
|
17
|
-
- Run#2 00:20-00:21
|
18
|
-
- etc
|
19
|
-
|
20
|
-
`RecurringActiveJob` 10 minute setting:
|
21
|
-
- Runs 10 minutes after the previous run finished
|
22
|
-
- Run#1 00:10-00:11
|
23
|
-
- Run#2 00:21-00:22
|
24
|
-
- etc
|
25
|
-
|
26
|
-
Use cases:
|
27
|
-
- Running jobs constantly without any delay in between
|
28
|
-
- Running jobs again some time after their execution
|
29
|
-
- Jobs where the execution time might be longer than the recurring timeframe
|
30
|
-
|
31
|
-
## Installation
|
32
|
-
|
33
|
-
Add this line to your application's Gemfile:
|
34
|
-
|
35
|
-
```ruby
|
36
|
-
gem 'recurring_active_job'
|
37
|
-
```
|
38
|
-
|
39
|
-
And then execute:
|
40
|
-
|
41
|
-
$ bundle
|
42
|
-
|
43
|
-
Or install it yourself as:
|
44
|
-
|
45
|
-
$ gem install recurring_active_job
|
46
|
-
|
47
|
-
## Usage
|
48
|
-
|
49
|
-
Recurring jobs are stored in the DB therefore we need the following migration:
|
50
|
-
|
51
|
-
```bash
|
52
|
-
bin/rails generate migration CreateRecurringActiveJob
|
53
|
-
```
|
54
|
-
|
55
|
-
`*_create_recurring_active_job.rb`
|
56
|
-
```ruby
|
57
|
-
def change
|
58
|
-
create_table :recurring_active_jobs do |t|
|
59
|
-
t.string :job_id
|
60
|
-
t.string :provider_job_id
|
61
|
-
t.boolean :active, default: true, null: false
|
62
|
-
t.integer :frequency_seconds, default: 600, null: false
|
63
|
-
t.boolean :auto_delete, default: true, null: false
|
64
|
-
t.string :last_error
|
65
|
-
t.text :last_error_details
|
66
|
-
|
67
|
-
t.timestamps
|
68
|
-
end
|
69
|
-
|
70
|
-
add_index :recurring_active_jobs, :job_id, unique: true
|
71
|
-
add_index :recurring_active_jobs, :provider_job_id, unique: true
|
72
|
-
end
|
73
|
-
```
|
74
|
-
|
75
|
-
Jobs need to subclass `RecurringActiveJob::Base` instead of `ActiveJob::Base`:
|
76
|
-
|
77
|
-
```ruby
|
78
|
-
class MyJob < RecurringActiveJob::Base
|
79
|
-
def perform(*args)
|
80
|
-
puts "hi"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
```
|
84
|
-
|
85
|
-
Create a `RecurringActiveJob::Model` record and pass its ID when performing the job:
|
86
|
-
|
87
|
-
```ruby
|
88
|
-
recurring_active_job = RecurringActiveJob::Model.create!(frequency_seconds: 10)
|
89
|
-
|
90
|
-
MyJob.perform_later(recurring_active_job_id: recurring_active_job.id)
|
91
|
-
```
|
92
|
-
|
93
|
-
### Testing
|
94
|
-
|
95
|
-
Make sure that the class properly inherits:
|
96
|
-
|
97
|
-
```ruby
|
98
|
-
describe MyJob
|
99
|
-
it "is a RecurringActiveJob" do
|
100
|
-
expect(described_class).to be < RecurringActiveJob::Base
|
101
|
-
end
|
102
|
-
end
|
103
|
-
```
|
104
|
-
|
105
|
-
Add a shared context to be included when testing Recurring jobs:
|
106
|
-
|
107
|
-
`spec/support/shared_context_for_recurring_active_job.rb`
|
108
|
-
```ruby
|
109
|
-
RSpec.shared_context "recurring active job" do
|
110
|
-
let(:recurring_active_job) { build_stubbed(:recurring_active_job) }
|
111
|
-
let(:recurring_active_job_params) { { recurring_active_job_id: recurring_active_job.id } }
|
112
|
-
|
113
|
-
before do
|
114
|
-
allow(RecurringActiveJob::Model).to receive(:find).and_return(recurring_active_job)
|
115
|
-
allow(recurring_active_job).to receive(:save!)
|
116
|
-
allow(recurring_active_job).to receive(:destroy!)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
```
|
120
|
-
|
121
|
-
```ruby
|
122
|
-
RSpec.describe MyJob do
|
123
|
-
describe "#perform" do
|
124
|
-
include_context "recurring active job"
|
125
|
-
# ...
|
126
|
-
end
|
127
|
-
end
|
128
|
-
```
|
129
|
-
|
130
|
-
## Feedback
|
131
|
-
|
132
|
-
Feedback is appreciated.
|
133
|
-
|
134
|
-
I can only tailor this project to fit use-cases I know about - which are usually my own ones. If you find that this might be the right direction to solve your problem too but you find that it's suboptimal or lacks features don't hesitate to contact me.
|
135
|
-
|
136
|
-
## Conventions
|
137
|
-
|
138
|
-
This gem is developed using the following conventions:
|
139
|
-
- [Bundler's guide for developing a gem](http://bundler.io/v1.14/guides/creating_gem.html)
|
140
|
-
- [Better Specs](http://www.betterspecs.org/)
|
141
|
-
- [Semantic versioning](http://semver.org/)
|
142
|
-
- [RubyGems' guide on gem naming](http://guides.rubygems.org/name-your-gem/)
|
143
|
-
- [RFC memo about key words used to Indicate Requirement Levels](https://tools.ietf.org/html/rfc2119)
|
144
|
-
- [Bundler improvements](https://github.com/thisismydesign/bundler-improvements)
|
145
|
-
- [Minimal dependencies](http://www.mikeperham.com/2016/02/09/kill-your-dependencies/)
|
146
|
-
|
147
|
-
## Contributing
|
148
|
-
|
149
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/thisismydesign/recurring_active_job.
|
150
|
-
|
151
|
-
## License
|
152
|
-
|
153
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
1
|
+
# RecurringActiveJob
|
2
|
+
|
3
|
+
#### Adapter agnostic ActiveJob scheduler based on time spent between executions.
|
4
|
+
|
5
|
+
<!--- Version informartion -->
|
6
|
+
*You are viewing the README of version [v0.3.0[0m](https://github.com/thisismydesign/recurring_active_job/releases/tag/v0.3.0[0m). You can find other releases [here](https://github.com/thisismydesign/recurring_active_job/releases).*
|
7
|
+
<!--- Version informartion end -->
|
8
|
+
|
9
|
+
| Branch | Status |
|
10
|
+
| ------ | ------ |
|
11
|
+
| Release | [![Build Status](https://travis-ci.org/thisismydesign/recurring_active_job.svg?branch=release)](https://travis-ci.org/thisismydesign/recurring_active_job) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/recurring_active_job/badge.svg?branch=release)](https://coveralls.io/github/thisismydesign/recurring_active_job?branch=release) [![Gem Version](https://badge.fury.io/rb/recurring_active_job.svg)](https://badge.fury.io/rb/recurring_active_job) [![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/recurring_active_job?type=total)](https://rubygems.org/gems/recurring_active_job) |
|
12
|
+
| Development | [![Build Status](https://travis-ci.org/thisismydesign/recurring_active_job.svg?branch=master)](https://travis-ci.org/thisismydesign/recurring_active_job) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/recurring_active_job/badge.svg?branch=master)](https://coveralls.io/github/thisismydesign/recurring_active_job?branch=master) |
|
13
|
+
|
14
|
+
Regular scheduler 10 minute setting:
|
15
|
+
- Runs every 10 minutes
|
16
|
+
- Run#1 00:10-00:11
|
17
|
+
- Run#2 00:20-00:21
|
18
|
+
- etc
|
19
|
+
|
20
|
+
`RecurringActiveJob` 10 minute setting:
|
21
|
+
- Runs 10 minutes after the previous run finished
|
22
|
+
- Run#1 00:10-00:11
|
23
|
+
- Run#2 00:21-00:22
|
24
|
+
- etc
|
25
|
+
|
26
|
+
Use cases:
|
27
|
+
- Running jobs constantly without any delay in between
|
28
|
+
- Running jobs again some time after their execution
|
29
|
+
- Jobs where the execution time might be longer than the recurring timeframe
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
Add this line to your application's Gemfile:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
gem 'recurring_active_job'
|
37
|
+
```
|
38
|
+
|
39
|
+
And then execute:
|
40
|
+
|
41
|
+
$ bundle
|
42
|
+
|
43
|
+
Or install it yourself as:
|
44
|
+
|
45
|
+
$ gem install recurring_active_job
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
Recurring jobs are stored in the DB therefore we need the following migration:
|
50
|
+
|
51
|
+
```bash
|
52
|
+
bin/rails generate migration CreateRecurringActiveJob
|
53
|
+
```
|
54
|
+
|
55
|
+
`*_create_recurring_active_job.rb`
|
56
|
+
```ruby
|
57
|
+
def change
|
58
|
+
create_table :recurring_active_jobs do |t|
|
59
|
+
t.string :job_id
|
60
|
+
t.string :provider_job_id
|
61
|
+
t.boolean :active, default: true, null: false
|
62
|
+
t.integer :frequency_seconds, default: 600, null: false
|
63
|
+
t.boolean :auto_delete, default: true, null: false
|
64
|
+
t.string :last_error
|
65
|
+
t.text :last_error_details
|
66
|
+
|
67
|
+
t.timestamps
|
68
|
+
end
|
69
|
+
|
70
|
+
add_index :recurring_active_jobs, :job_id, unique: true
|
71
|
+
add_index :recurring_active_jobs, :provider_job_id, unique: true
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
Jobs need to subclass `RecurringActiveJob::Base` instead of `ActiveJob::Base`:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
class MyJob < RecurringActiveJob::Base
|
79
|
+
def perform(*args)
|
80
|
+
puts "hi"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
Create a `RecurringActiveJob::Model` record and pass its ID when performing the job:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
recurring_active_job = RecurringActiveJob::Model.create!(frequency_seconds: 10)
|
89
|
+
|
90
|
+
MyJob.perform_later(recurring_active_job_id: recurring_active_job.id)
|
91
|
+
```
|
92
|
+
|
93
|
+
### Testing
|
94
|
+
|
95
|
+
Make sure that the class properly inherits:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
describe MyJob
|
99
|
+
it "is a RecurringActiveJob" do
|
100
|
+
expect(described_class).to be < RecurringActiveJob::Base
|
101
|
+
end
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
Add a shared context to be included when testing Recurring jobs:
|
106
|
+
|
107
|
+
`spec/support/shared_context_for_recurring_active_job.rb`
|
108
|
+
```ruby
|
109
|
+
RSpec.shared_context "recurring active job" do
|
110
|
+
let(:recurring_active_job) { build_stubbed(:recurring_active_job) }
|
111
|
+
let(:recurring_active_job_params) { { recurring_active_job_id: recurring_active_job.id } }
|
112
|
+
|
113
|
+
before do
|
114
|
+
allow(RecurringActiveJob::Model).to receive(:find).and_return(recurring_active_job)
|
115
|
+
allow(recurring_active_job).to receive(:save!)
|
116
|
+
allow(recurring_active_job).to receive(:destroy!)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
RSpec.describe MyJob do
|
123
|
+
describe "#perform" do
|
124
|
+
include_context "recurring active job"
|
125
|
+
# ...
|
126
|
+
end
|
127
|
+
end
|
128
|
+
```
|
129
|
+
|
130
|
+
## Feedback
|
131
|
+
|
132
|
+
Feedback is appreciated.
|
133
|
+
|
134
|
+
I can only tailor this project to fit use-cases I know about - which are usually my own ones. If you find that this might be the right direction to solve your problem too but you find that it's suboptimal or lacks features don't hesitate to contact me.
|
135
|
+
|
136
|
+
## Conventions
|
137
|
+
|
138
|
+
This gem is developed using the following conventions:
|
139
|
+
- [Bundler's guide for developing a gem](http://bundler.io/v1.14/guides/creating_gem.html)
|
140
|
+
- [Better Specs](http://www.betterspecs.org/)
|
141
|
+
- [Semantic versioning](http://semver.org/)
|
142
|
+
- [RubyGems' guide on gem naming](http://guides.rubygems.org/name-your-gem/)
|
143
|
+
- [RFC memo about key words used to Indicate Requirement Levels](https://tools.ietf.org/html/rfc2119)
|
144
|
+
- [Bundler improvements](https://github.com/thisismydesign/bundler-improvements)
|
145
|
+
- [Minimal dependencies](http://www.mikeperham.com/2016/02/09/kill-your-dependencies/)
|
146
|
+
|
147
|
+
## Contributing
|
148
|
+
|
149
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/thisismydesign/recurring_active_job.
|
150
|
+
|
151
|
+
## License
|
152
|
+
|
153
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
File without changes
|
data/bin/console
CHANGED
File without changes
|
data/bin/setup
CHANGED
File without changes
|
data/config/database.yml
CHANGED
File without changes
|
File without changes
|
data/config/schema.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
# This file is auto-generated from the current state of the database. Instead
|
2
|
-
# of editing this file, please use the migrations feature of Active Record to
|
3
|
-
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
-
#
|
5
|
-
# Note that this schema.rb definition is the authoritative source for your
|
6
|
-
# database schema. If you need to create the application database on another
|
7
|
-
# system, you should be using db:schema:load, not running all the migrations
|
8
|
-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
-
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
-
#
|
11
|
-
# It's strongly recommended that you check this file into your version control system.
|
12
|
-
|
13
|
-
ActiveRecord::Schema.define(version: 2018_06_27_123939) do
|
14
|
-
|
15
|
-
create_table "recurring_active_jobs", force: :cascade do |t|
|
16
|
-
t.string "job_id"
|
17
|
-
t.string "provider_job_id"
|
18
|
-
t.boolean "active", default: true, null: false
|
19
|
-
t.integer "frequency_seconds", default: 600, null: false
|
20
|
-
t.boolean "auto_delete", default: true, null: false
|
21
|
-
t.string "last_error"
|
22
|
-
t.text "last_error_details"
|
23
|
-
t.datetime "created_at", null: false
|
24
|
-
t.datetime "updated_at", null: false
|
25
|
-
t.index ["job_id"], name: "index_recurring_active_jobs_on_job_id", unique: true
|
26
|
-
t.index ["provider_job_id"], name: "index_recurring_active_jobs_on_provider_job_id", unique: true
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
6
|
+
# database schema. If you need to create the application database on another
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
+
#
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(version: 2018_06_27_123939) do
|
14
|
+
|
15
|
+
create_table "recurring_active_jobs", force: :cascade do |t|
|
16
|
+
t.string "job_id"
|
17
|
+
t.string "provider_job_id"
|
18
|
+
t.boolean "active", default: true, null: false
|
19
|
+
t.integer "frequency_seconds", default: 600, null: false
|
20
|
+
t.boolean "auto_delete", default: true, null: false
|
21
|
+
t.string "last_error"
|
22
|
+
t.text "last_error_details"
|
23
|
+
t.datetime "created_at", null: false
|
24
|
+
t.datetime "updated_at", null: false
|
25
|
+
t.index ["job_id"], name: "index_recurring_active_jobs_on_job_id", unique: true
|
26
|
+
t.index ["provider_job_id"], name: "index_recurring_active_jobs_on_provider_job_id", unique: true
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -1,80 +1,84 @@
|
|
1
|
-
require "active_job"
|
2
|
-
|
3
|
-
module RecurringActiveJob
|
4
|
-
class Base < ActiveJob::Base
|
5
|
-
class << self
|
6
|
-
attr_accessor :logger
|
7
|
-
end
|
8
|
-
|
9
|
-
retry_on(StandardError, attempts: 0) do |job, e|
|
10
|
-
recurring_active_job = RecurringActiveJob::Model.find(job.arguments.first&.dig(:recurring_active_job_id))
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
raise
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
def
|
68
|
-
"
|
69
|
-
end
|
70
|
-
|
71
|
-
def
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
1
|
+
require "active_job"
|
2
|
+
|
3
|
+
module RecurringActiveJob
|
4
|
+
class Base < ActiveJob::Base
|
5
|
+
class << self
|
6
|
+
attr_accessor :logger
|
7
|
+
end
|
8
|
+
|
9
|
+
retry_on(StandardError, attempts: 0) do |job, e|
|
10
|
+
recurring_active_job = RecurringActiveJob::Model.find(job.arguments.first&.dig(:recurring_active_job_id))
|
11
|
+
if ActiveJob.gem_version < Gem::Version.new("5.2.0")
|
12
|
+
recurring_active_job.update!(last_error: e, last_error_details: e)
|
13
|
+
else
|
14
|
+
recurring_active_job.update!(last_error: "#{e.class}: #{e.message}", last_error_details: ruby_style_error(e))
|
15
|
+
end
|
16
|
+
raise e
|
17
|
+
end
|
18
|
+
|
19
|
+
before_enqueue do |job|
|
20
|
+
raise "Missing `recurring_active_job_id` argument" unless job.arguments.first&.dig(:recurring_active_job_id)
|
21
|
+
load_recurring_active_job(job.arguments.first&.dig(:recurring_active_job_id))
|
22
|
+
@recurring_active_job.job_id = job.job_id
|
23
|
+
@recurring_active_job.save!
|
24
|
+
end
|
25
|
+
|
26
|
+
after_enqueue do |job|
|
27
|
+
# provider_job_id is first available after enqueue
|
28
|
+
@recurring_active_job.provider_job_id = job.provider_job_id
|
29
|
+
@recurring_active_job.save!
|
30
|
+
end
|
31
|
+
|
32
|
+
before_perform do |job|
|
33
|
+
load_recurring_active_job(job.arguments.first[:recurring_active_job_id])
|
34
|
+
logger&.debug("Performing #{job_info(job)}")
|
35
|
+
end
|
36
|
+
|
37
|
+
after_perform do |job|
|
38
|
+
requeue(job)
|
39
|
+
clean
|
40
|
+
end
|
41
|
+
|
42
|
+
def perform(*args); end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def load_recurring_active_job(id)
|
47
|
+
@recurring_active_job ||= RecurringActiveJob::Model.find(id)
|
48
|
+
end
|
49
|
+
|
50
|
+
def requeue(job)
|
51
|
+
unless @recurring_active_job.active
|
52
|
+
logger&.info("#{recurring_active_job_info} was deactivated and is not requeued")
|
53
|
+
return
|
54
|
+
end
|
55
|
+
|
56
|
+
requeued_job = self.class.set(queue: job.queue_name, wait: @recurring_active_job.frequency_seconds.seconds).perform_later(job.arguments.first)
|
57
|
+
logger&.debug("Requeued #{job_info(requeued_job)}")
|
58
|
+
end
|
59
|
+
|
60
|
+
def clean
|
61
|
+
return if @recurring_active_job.active
|
62
|
+
return unless @recurring_active_job.auto_delete
|
63
|
+
logger&.debug("Destroying #{recurring_active_job_info}")
|
64
|
+
@recurring_active_job.destroy!
|
65
|
+
end
|
66
|
+
|
67
|
+
def job_info(job)
|
68
|
+
recurring_active_job_info + " job #{job.job_id} in queue #{job.queue_name}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def recurring_active_job_info
|
72
|
+
"RecurringActiveJob##{@recurring_active_job.id}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def logger
|
76
|
+
self.class.logger
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.ruby_style_error(e)
|
80
|
+
e.backtrace.join("\n\t")
|
81
|
+
.sub("\n\t", ": #{e}#{e.class ? " (#{e.class})" : ''}\n\t")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
File without changes
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module RecurringActiveJob
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
1
|
+
module RecurringActiveJob
|
2
|
+
VERSION = "0.3.0"
|
3
|
+
end
|
data/lib/recurring_active_job.rb
CHANGED
File without changes
|
@@ -1,41 +1,41 @@
|
|
1
|
-
lib = File.expand_path("../lib", __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require "recurring_active_job/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "recurring_active_job"
|
7
|
-
spec.version = RecurringActiveJob::VERSION
|
8
|
-
spec.authors = ["thisismydesign"]
|
9
|
-
spec.email = ["git.thisismydesign@gmail.com"]
|
10
|
-
|
11
|
-
spec.summary = ""
|
12
|
-
spec.homepage = ""
|
13
|
-
spec.license = "MIT"
|
14
|
-
|
15
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
-
f.match(%r{^(test|spec|features)/})
|
17
|
-
end
|
18
|
-
spec.bindir = "exe"
|
19
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = ["lib"]
|
21
|
-
|
22
|
-
spec.add_dependency "activejob"
|
23
|
-
spec.add_dependency "activerecord"
|
24
|
-
|
25
|
-
spec.add_development_dependency "sqlite3"
|
26
|
-
|
27
|
-
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
-
spec.add_development_dependency 'rspec-rails', '~> 3.7'
|
31
|
-
spec.add_development_dependency "coveralls"
|
32
|
-
spec.add_development_dependency "timecop"
|
33
|
-
spec.add_development_dependency "guard"
|
34
|
-
spec.add_development_dependency "guard-bundler"
|
35
|
-
spec.add_development_dependency "guard-rspec"
|
36
|
-
spec.add_development_dependency "guard-rubocop"
|
37
|
-
spec.add_development_dependency "autowow"
|
38
|
-
spec.add_development_dependency "rubocop"
|
39
|
-
spec.add_development_dependency "rubocop-rspec"
|
40
|
-
spec.add_development_dependency 'factory_bot_rails', ">= 4.8.1" # https://github.com/thoughtbot/factory_bot/pull/982
|
41
|
-
end
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "recurring_active_job/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "recurring_active_job"
|
7
|
+
spec.version = RecurringActiveJob::VERSION
|
8
|
+
spec.authors = ["thisismydesign"]
|
9
|
+
spec.email = ["git.thisismydesign@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = ""
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "activejob", ">= 5.0.0" # Usage of `retry_on`
|
23
|
+
spec.add_dependency "activerecord"
|
24
|
+
|
25
|
+
spec.add_development_dependency "sqlite3"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency 'rspec-rails', '~> 3.7'
|
31
|
+
spec.add_development_dependency "coveralls"
|
32
|
+
spec.add_development_dependency "timecop"
|
33
|
+
spec.add_development_dependency "guard"
|
34
|
+
spec.add_development_dependency "guard-bundler"
|
35
|
+
spec.add_development_dependency "guard-rspec"
|
36
|
+
spec.add_development_dependency "guard-rubocop"
|
37
|
+
spec.add_development_dependency "autowow"
|
38
|
+
spec.add_development_dependency "rubocop"
|
39
|
+
spec.add_development_dependency "rubocop-rspec"
|
40
|
+
spec.add_development_dependency 'factory_bot_rails', ">= 4.8.1" # https://github.com/thoughtbot/factory_bot/pull/982
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recurring_active_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thisismydesign
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 5.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -293,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
293
293
|
version: '0'
|
294
294
|
requirements: []
|
295
295
|
rubyforge_project:
|
296
|
-
rubygems_version: 2.7.
|
296
|
+
rubygems_version: 2.7.7
|
297
297
|
signing_key:
|
298
298
|
specification_version: 4
|
299
299
|
summary: ''
|