marj 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +69 -32
- data/lib/marj.rb +3 -1
- data/lib/marj_adapter.rb +2 -0
- data/lib/marj_config.rb +2 -0
- data/{app/models/marj.rb → lib/marj_record.rb} +6 -9
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42a85f9f7752849bf9e7781eef989294d45420763c16fb5fadee3df3fc7a0c2e
|
4
|
+
data.tar.gz: acadf4b197599bd3150629a557857b8d48fa8bed662a2f4140a8dbe16f01e7ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a30fe477c647ca284fdcde1bcccc8b000f3b4ef78b62de84f486376fa65450fcf3a52c7132df520fd45ee7e0f2856d8812a16b804ce89baa93a8d2353dc8348f
|
7
|
+
data.tar.gz: 72a63c15a36f6bade30e93bb5f84d5d8c6bbab33b12f4c92c78579f07eb86689e8e7609dae9ec16b94334140e8e4c2828b6e6cb19a580ad9a42730f27afab8cb
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
# Marj
|
1
|
+
# Marj - Minimal ActiveRecord Jobs
|
2
2
|
|
3
|
-
|
3
|
+
The simplest database-backed ActiveJob queueing backend.
|
4
|
+
|
5
|
+
## Quick Links
|
4
6
|
|
5
7
|
API docs: https://www.rubydoc.info/github/nicholasdower/marj <br>
|
6
8
|
RubyGems: https://rubygems.org/gems/marj <br>
|
@@ -8,27 +10,52 @@ Changelog: https://github.com/nicholasdower/marj/releases <br>
|
|
8
10
|
Issues: https://github.com/nicholasdower/marj/issues <br>
|
9
11
|
Development: https://github.com/nicholasdower/marj/blob/master/CONTRIBUTING.md
|
10
12
|
|
11
|
-
|
13
|
+
## Features
|
12
14
|
|
13
|
-
-
|
14
|
-
-
|
15
|
-
-
|
15
|
+
- Enqueued jobs are written to the database.
|
16
|
+
- Successfully executed jobs are deleted from the database.
|
17
|
+
- Failed jobs which should be retried are updated in the database.
|
18
|
+
- Failed jobs which should not be retried are deleted from the database.
|
19
|
+
|
20
|
+
## Features Not Provided
|
21
|
+
|
22
|
+
- Workers
|
23
|
+
- Timeouts
|
24
|
+
- Concurrency Controls
|
25
|
+
- Observability
|
26
|
+
- A User Interace
|
27
|
+
- Anything else you might dream up.
|
28
|
+
|
29
|
+
## Interface
|
30
|
+
|
31
|
+
- `Marj` - An ActiveRecord model class
|
32
|
+
- `Marj.ready` - Used to retrieve jobs ready to be executed
|
33
|
+
- `Marj#execute` - Used to execute jobs retrieved from the database
|
34
|
+
- `MarjConfig.table_name=` - Used to override the default table name
|
16
35
|
|
17
36
|
## Setup
|
18
37
|
|
19
38
|
### 1. Install
|
20
39
|
|
21
|
-
|
40
|
+
```shell
|
41
|
+
bundle add marj
|
22
42
|
|
23
|
-
|
24
|
-
|
43
|
+
# or
|
44
|
+
|
45
|
+
gem install marj
|
25
46
|
```
|
26
47
|
|
27
|
-
|
28
|
-
|
48
|
+
### 2. Configure
|
49
|
+
|
50
|
+
By default, the database table is named "jobs". To use a different table name:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
require 'marj'
|
54
|
+
|
55
|
+
MarjConfig.table_name = 'some_name'
|
29
56
|
```
|
30
57
|
|
31
|
-
###
|
58
|
+
### 3. Create the database table
|
32
59
|
|
33
60
|
```ruby
|
34
61
|
class CreateJobs < ActiveRecord::Migration[7.1]
|
@@ -57,15 +84,7 @@ class CreateJobs < ActiveRecord::Migration[7.1]
|
|
57
84
|
end
|
58
85
|
```
|
59
86
|
|
60
|
-
|
61
|
-
|
62
|
-
```ruby
|
63
|
-
require 'marj'
|
64
|
-
|
65
|
-
MarjConfig.table_name = 'some_name'
|
66
|
-
```
|
67
|
-
|
68
|
-
### 3. Configure the queue adapter
|
87
|
+
### 4. Configure the queue adapter
|
69
88
|
|
70
89
|
```ruby
|
71
90
|
require 'marj'
|
@@ -93,28 +112,40 @@ job.perform_now
|
|
93
112
|
|
94
113
|
# Enqueue, retrieve and manually run a job:
|
95
114
|
SomeJob.perform_later('foo')
|
96
|
-
|
97
|
-
record.execute
|
115
|
+
Marj.first.execute
|
98
116
|
|
99
117
|
# Run all ready jobs:
|
100
|
-
|
101
|
-
|
102
|
-
|
118
|
+
Marj.ready.each(&:execute)
|
119
|
+
|
120
|
+
# Run all ready jobs, querying each time:
|
121
|
+
loop { Marj.ready.first&.tap(&:execute) || break }
|
103
122
|
|
104
123
|
# Run all ready jobs in a specific queue:
|
105
|
-
|
106
|
-
record.execute
|
107
|
-
end
|
124
|
+
loop { Marj.where(queue_name: 'foo').ready.first&.tap(&:execute) || break }
|
108
125
|
|
109
126
|
# Run jobs as they become ready:
|
110
127
|
loop do
|
111
|
-
|
112
|
-
|
113
|
-
|
128
|
+
loop { Marj.ready.first&.tap(&:execute) || break }
|
129
|
+
rescue Exception => e
|
130
|
+
logger.error(e)
|
131
|
+
ensure
|
114
132
|
sleep 5.seconds
|
115
133
|
end
|
116
134
|
```
|
117
135
|
|
136
|
+
## Testing
|
137
|
+
|
138
|
+
By default, jobs enqeued during tests will be written to the database. Enqueued jobs can be executed via:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
Marj.ready.each(&:execute)
|
142
|
+
```
|
143
|
+
|
144
|
+
Alternatively, to use [ActiveJob::QueueAdapters::TestAdapter](https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters/TestAdapter.html):
|
145
|
+
```ruby
|
146
|
+
ActiveJob::Base.queue_adapter = :test
|
147
|
+
```
|
148
|
+
|
118
149
|
## Extension Examples
|
119
150
|
|
120
151
|
### Timeouts
|
@@ -176,6 +207,12 @@ end
|
|
176
207
|
|
177
208
|
## ActiveJob Cheatsheet
|
178
209
|
|
210
|
+
For more information on ActiveJob, see:
|
211
|
+
|
212
|
+
- https://edgeguides.rubyonrails.org/active_job_basics.html
|
213
|
+
- https://www.rubydoc.info/gems/activejob
|
214
|
+
- https://github.com/nicholasdower/marj/blob/master/README.md#activejob-cheatsheet
|
215
|
+
|
179
216
|
### Configuring a Queue Adapter
|
180
217
|
|
181
218
|
```ruby
|
data/lib/marj.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# See https://github.com/nicholasdower/marj
|
4
|
+
|
3
5
|
require_relative 'marj_adapter'
|
4
6
|
require_relative 'marj_config'
|
5
7
|
|
6
|
-
Kernel.autoload(:Marj, File.expand_path('
|
8
|
+
Kernel.autoload(:Marj, File.expand_path('marj_record.rb', __dir__))
|
data/lib/marj_adapter.rb
CHANGED
data/lib/marj_config.rb
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'active_job'
|
4
4
|
require 'active_record'
|
5
|
-
require_relative '
|
5
|
+
require_relative 'marj_config'
|
6
6
|
|
7
|
-
# Marj
|
7
|
+
# The Marj ActiveRecord model class.
|
8
8
|
#
|
9
9
|
# See https://github.com/nicholasdower/marj
|
10
10
|
class Marj < ActiveRecord::Base
|
11
11
|
# The Marj version.
|
12
|
-
VERSION = '2.0.
|
12
|
+
VERSION = '2.0.1'
|
13
13
|
|
14
14
|
# Executes the job associated with this record and returns the result.
|
15
15
|
def execute
|
@@ -29,13 +29,9 @@ class Marj < ActiveRecord::Base
|
|
29
29
|
|
30
30
|
# ActiveJob::Base#deserialize expects dates to be strings rather than Time objects.
|
31
31
|
job_data = job_data.to_h { |k, v| [k, %w[enqueued_at scheduled_at].include?(k) ? v&.iso8601 : v] }
|
32
|
-
job.deserialize(job_data)
|
33
32
|
|
34
|
-
|
35
|
-
job.perform_now
|
36
|
-
# If no error was raised, the job should either be destroyed (success) or updated (retryable failure).
|
37
|
-
raise "job #{job_id} not destroyed or updated" unless destroyed? || (executions == new_executions && !changed?)
|
38
|
-
end
|
33
|
+
job.deserialize(job_data)
|
34
|
+
job.perform_now
|
39
35
|
end
|
40
36
|
end
|
41
37
|
|
@@ -106,6 +102,7 @@ class Marj < ActiveRecord::Base
|
|
106
102
|
job.singleton_class.after_perform { |_j| record.destroy! }
|
107
103
|
job.singleton_class.after_discard { |_j, _exception| record.destroy! }
|
108
104
|
job.singleton_class.instance_variable_set(:@__marj, record)
|
105
|
+
|
109
106
|
job
|
110
107
|
end
|
111
108
|
private_class_method :register_callbacks
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Dower
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -38,7 +38,8 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '7.1'
|
41
|
-
description: Minimal ActiveRecord
|
41
|
+
description: Marj (Minimal ActiveRecord Jobs) is the simplest database-backed ActiveJob
|
42
|
+
queueing backend.
|
42
43
|
email: nicholasdower@gmail.com
|
43
44
|
executables: []
|
44
45
|
extensions: []
|
@@ -46,17 +47,17 @@ extra_rdoc_files: []
|
|
46
47
|
files:
|
47
48
|
- LICENSE.txt
|
48
49
|
- README.md
|
49
|
-
- app/models/marj.rb
|
50
50
|
- lib/marj.rb
|
51
51
|
- lib/marj_adapter.rb
|
52
52
|
- lib/marj_config.rb
|
53
|
+
- lib/marj_record.rb
|
53
54
|
homepage: https://github.com/nicholasdower/marj
|
54
55
|
licenses:
|
55
56
|
- MIT
|
56
57
|
metadata:
|
57
58
|
bug_tracker_uri: https://github.com/nicholasdower/marj/issues
|
58
|
-
changelog_uri: https://github.com/nicholasdower/marj/releases/tag/v2.0.
|
59
|
-
documentation_uri: https://www.rubydoc.info/github/nicholasdower/marj/v2.0.
|
59
|
+
changelog_uri: https://github.com/nicholasdower/marj/releases/tag/v2.0.1
|
60
|
+
documentation_uri: https://www.rubydoc.info/github/nicholasdower/marj/v2.0.1
|
60
61
|
homepage_uri: https://github.com/nicholasdower/marj
|
61
62
|
rubygems_mfa_required: 'true'
|
62
63
|
source_code_uri: https://github.com/nicholasdower/marj
|
@@ -78,5 +79,5 @@ requirements: []
|
|
78
79
|
rubygems_version: 3.5.3
|
79
80
|
signing_key:
|
80
81
|
specification_version: 4
|
81
|
-
summary:
|
82
|
+
summary: Minimal ActiveRecord Jobs
|
82
83
|
test_files: []
|