marj 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/marj_record.rb +21 -8
- 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: '078c3d48b27784e09425ba8eda2207038d6ce5c7a711953e8567c76aac689435'
|
4
|
+
data.tar.gz: c129b4848de1e2fe55de0de3a4893586a052cd814df798879dc196a81c1a94d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cef48fb7c862123f4a5ad7ed5bf7a9d95eb3d7036831db79ad3dc9cf94f074a112ce58f0189484f991a52185cdf8e8ceed48dd9237bf4a04d5e3bbe30b2d274
|
7
|
+
data.tar.gz: 7631b1a0fef1ece1edcf15541dc85d25b2d5d3ba1cb8ca716133975126e5ce9bb4f28d627a4c2a5d751029ce8f67ba4db47c6fa9d197467fade4c09d20a04716
|
data/README.md
CHANGED
data/lib/marj_record.rb
CHANGED
@@ -9,7 +9,7 @@ require_relative 'marj_config'
|
|
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.1.0'
|
13
13
|
|
14
14
|
# Executes the job associated with this record and returns the result.
|
15
15
|
def execute
|
@@ -93,14 +93,18 @@ class Marj < ActiveRecord::Base
|
|
93
93
|
# @param job [ActiveJob::Base]
|
94
94
|
# @return [ActiveJob::Base]
|
95
95
|
def self.register_callbacks(job, record)
|
96
|
-
|
96
|
+
if job.singleton_class.instance_variable_get(:@__marj)
|
97
|
+
# Callbacks already registered. We just need to update the record.
|
98
|
+
job.singleton_class.instance_variable_set(:@__marj, record)
|
99
|
+
return
|
100
|
+
end
|
97
101
|
|
98
102
|
# We need to detect three cases:
|
99
103
|
# - If a job succeeds, after_perform will be called.
|
100
104
|
# - If a job fails and should be retried, enqueue will be called. This is handled by the enqueue method.
|
101
105
|
# - If a job exceeds its max attempts, after_discard will be called.
|
102
|
-
job.singleton_class.after_perform { |_j|
|
103
|
-
job.singleton_class.after_discard { |_j, _exception|
|
106
|
+
job.singleton_class.after_perform { |_j| job.singleton_class.instance_variable_get(:@__marj).destroy! }
|
107
|
+
job.singleton_class.after_discard { |_j, _exception| job.singleton_class.instance_variable_get(:@__marj).destroy! }
|
104
108
|
job.singleton_class.instance_variable_set(:@__marj, record)
|
105
109
|
|
106
110
|
job
|
@@ -121,19 +125,28 @@ class Marj < ActiveRecord::Base
|
|
121
125
|
# registered on the job instance so that when the job is executed, the database record is deleted or updated
|
122
126
|
# (depending on the result).
|
123
127
|
#
|
124
|
-
# There are
|
128
|
+
# There are two normal cases:
|
125
129
|
# - The first time a job is enqueued, we need to create the record and register callbacks.
|
126
130
|
# - If a previously enqueued job instance is re-enqueued, for instance after execution fails, callbacks have
|
127
131
|
# already been registered. In this case we only need to update the record.
|
128
|
-
# - It is also possible for new job instance to be created for a job that is already in the database. In this case
|
129
|
-
# we need to update the record and register callbacks.
|
130
132
|
#
|
131
133
|
# We keep track of whether callbacks have been registered by setting the @__marj instance variable on the job's
|
132
134
|
# singleton class. This holds a reference to the record. This allows us to update the record without re-fetching it
|
133
135
|
# and also ensures that if execute is called on a record any updates to the database are reflected on that record
|
134
136
|
# instance.
|
137
|
+
#
|
138
|
+
# There are also two edge cases:
|
139
|
+
# - It is possible for new job instance to be created for a job that is already in the database. In this case
|
140
|
+
# we need to update the record and register callbacks.
|
141
|
+
# - It is possible for the underlying row corresponding to an existing job to have been deleted. In this case we
|
142
|
+
# need to create a new record and update the reference on the job's singleton class.
|
135
143
|
if (record = job.singleton_class.instance_variable_get(:@__marj))
|
136
|
-
|
144
|
+
if Marj.exists?(job_id: job.job_id)
|
145
|
+
record.update!(serialized)
|
146
|
+
else
|
147
|
+
record = Marj.create!(serialized)
|
148
|
+
register_callbacks(job, record)
|
149
|
+
end
|
137
150
|
else
|
138
151
|
record = Marj.find_or_create_by!(job_id: job.job_id) { _1.assign_attributes(serialized) }
|
139
152
|
register_callbacks(job, record)
|
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.1.0
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -56,8 +56,8 @@ licenses:
|
|
56
56
|
- MIT
|
57
57
|
metadata:
|
58
58
|
bug_tracker_uri: https://github.com/nicholasdower/marj/issues
|
59
|
-
changelog_uri: https://github.com/nicholasdower/marj/releases/tag/v2.0
|
60
|
-
documentation_uri: https://www.rubydoc.info/github/nicholasdower/marj/v2.0
|
59
|
+
changelog_uri: https://github.com/nicholasdower/marj/releases/tag/v2.1.0
|
60
|
+
documentation_uri: https://www.rubydoc.info/github/nicholasdower/marj/v2.1.0
|
61
61
|
homepage_uri: https://github.com/nicholasdower/marj
|
62
62
|
rubygems_mfa_required: 'true'
|
63
63
|
source_code_uri: https://github.com/nicholasdower/marj
|