active_job_log 0.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +24 -0
- data/Gemfile.lock +13 -48
- data/README.md +4 -0
- data/active_job_log.gemspec +0 -1
- data/db/migrate/20180511184635_create_active_job_log_jobs.rb +1 -1
- data/lib/active_job_log/engine.rb +1 -0
- data/lib/active_job_log/loggeable.rb +72 -0
- data/lib/active_job_log/version.rb +1 -1
- data/lib/generators/active_job_log/install/install_generator.rb +4 -0
- data/lib/generators/active_job_log/install/templates/job_model.rb +5 -0
- data/spec/dummy/app/models/active_job_log/job.rb +5 -0
- data/spec/dummy/db/schema.rb +1 -1
- data/spec/models/active_job_log/job_spec.rb +26 -35
- metadata +48 -60
- data/app/models/active_job_log/job.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f1818ddd9d4d8fa579bdb5a4486f6d25ab66405c756de6624d809b1cf080978
|
4
|
+
data.tar.gz: f9bac28b1eeed244318904ae769c3f310208e162cae60c6d198969e1bdc259d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75e5518a0358f84f69871f4b4db2f11885bcc20184980a7009778020cb92c88c9a410276d4e4cc271f3586dca075be22d04aa6671ee36a896d29cb6d6cec9c85
|
7
|
+
data.tar.gz: fb5200fea9ab357547feeea42d22ccdc43e77351d50ea2b86100c343302bcd1b8ff40325d1451de0c2066d96b819c167c55e28799ec7455f425845e701e7ab41
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,30 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
### v1.2.0
|
6
|
+
|
7
|
+
#### Changed
|
8
|
+
|
9
|
+
* Use update instead of deprecated update_attributes.
|
10
|
+
|
11
|
+
### v1.0.0
|
12
|
+
|
13
|
+
#### Changed
|
14
|
+
|
15
|
+
* Copy Job model into app.
|
16
|
+
|
17
|
+
### v0.2.1
|
18
|
+
|
19
|
+
#### Fixed
|
20
|
+
|
21
|
+
* Change error type from string to text.
|
22
|
+
|
23
|
+
### v0.2.0
|
24
|
+
|
25
|
+
#### Added
|
26
|
+
|
27
|
+
* New Job instance by retry.
|
28
|
+
|
5
29
|
### v0.1.0
|
6
30
|
|
7
31
|
* Initial release.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active_job_log (
|
4
|
+
active_job_log (1.2.0)
|
5
5
|
enumerize (>= 1.0)
|
6
6
|
rails (>= 4.2.0)
|
7
7
|
|
@@ -62,7 +62,7 @@ GEM
|
|
62
62
|
crass (1.0.4)
|
63
63
|
diff-lcs (1.3)
|
64
64
|
docile (1.1.5)
|
65
|
-
enumerize (2.
|
65
|
+
enumerize (2.4.0)
|
66
66
|
activesupport (>= 3.2)
|
67
67
|
erubi (1.7.1)
|
68
68
|
factory_bot (4.8.2)
|
@@ -70,51 +70,26 @@ GEM
|
|
70
70
|
factory_bot_rails (4.8.2)
|
71
71
|
factory_bot (~> 4.8.2)
|
72
72
|
railties (>= 3.0.0)
|
73
|
-
|
74
|
-
formatador (0.2.5)
|
75
|
-
globalid (0.4.1)
|
73
|
+
globalid (0.4.2)
|
76
74
|
activesupport (>= 4.2.0)
|
77
|
-
guard (2.14.2)
|
78
|
-
formatador (>= 0.2.4)
|
79
|
-
listen (>= 2.7, < 4.0)
|
80
|
-
lumberjack (>= 1.0.12, < 2.0)
|
81
|
-
nenv (~> 0.1)
|
82
|
-
notiffany (~> 0.0)
|
83
|
-
pry (>= 0.9.12)
|
84
|
-
shellany (~> 0.0)
|
85
|
-
thor (>= 0.18.1)
|
86
|
-
guard-compat (1.2.1)
|
87
|
-
guard-rspec (4.7.3)
|
88
|
-
guard (~> 2.1)
|
89
|
-
guard-compat (~> 1.1)
|
90
|
-
rspec (>= 2.99.0, < 4.0)
|
91
75
|
i18n (1.0.1)
|
92
76
|
concurrent-ruby (~> 1.0)
|
93
77
|
json (2.1.0)
|
94
|
-
listen (3.1.5)
|
95
|
-
rb-fsevent (~> 0.9, >= 0.9.4)
|
96
|
-
rb-inotify (~> 0.9, >= 0.9.7)
|
97
|
-
ruby_dep (~> 1.2)
|
98
78
|
loofah (2.2.2)
|
99
79
|
crass (~> 1.0.2)
|
100
80
|
nokogiri (>= 1.5.9)
|
101
|
-
|
102
|
-
mail (2.7.0)
|
81
|
+
mail (2.7.1)
|
103
82
|
mini_mime (>= 0.1.1)
|
104
|
-
marcel (0.3.
|
83
|
+
marcel (0.3.3)
|
105
84
|
mimemagic (~> 0.3.2)
|
106
85
|
method_source (0.9.0)
|
107
|
-
mimemagic (0.3.
|
108
|
-
mini_mime (1.0.
|
86
|
+
mimemagic (0.3.5)
|
87
|
+
mini_mime (1.0.2)
|
109
88
|
mini_portile2 (2.3.0)
|
110
89
|
minitest (5.11.3)
|
111
|
-
|
112
|
-
nio4r (2.3.1)
|
90
|
+
nio4r (2.5.2)
|
113
91
|
nokogiri (1.8.2)
|
114
92
|
mini_portile2 (~> 2.3.0)
|
115
|
-
notiffany (0.1.1)
|
116
|
-
nenv (~> 0.1)
|
117
|
-
shellany (~> 0.0)
|
118
93
|
pry (0.11.3)
|
119
94
|
coderay (~> 1.1.0)
|
120
95
|
method_source (~> 0.9.0)
|
@@ -148,13 +123,6 @@ GEM
|
|
148
123
|
rake (>= 0.8.7)
|
149
124
|
thor (>= 0.18.1, < 2.0)
|
150
125
|
rake (12.3.1)
|
151
|
-
rb-fsevent (0.10.3)
|
152
|
-
rb-inotify (0.9.10)
|
153
|
-
ffi (>= 0.5.0, < 2)
|
154
|
-
rspec (3.7.0)
|
155
|
-
rspec-core (~> 3.7.0)
|
156
|
-
rspec-expectations (~> 3.7.0)
|
157
|
-
rspec-mocks (~> 3.7.0)
|
158
126
|
rspec-core (3.7.1)
|
159
127
|
rspec-support (~> 3.7.0)
|
160
128
|
rspec-expectations (3.7.0)
|
@@ -172,17 +140,15 @@ GEM
|
|
172
140
|
rspec-mocks (~> 3.7.0)
|
173
141
|
rspec-support (~> 3.7.0)
|
174
142
|
rspec-support (3.7.1)
|
175
|
-
ruby_dep (1.5.0)
|
176
|
-
shellany (0.0.1)
|
177
143
|
simplecov (0.14.1)
|
178
144
|
docile (~> 1.1.0)
|
179
145
|
json (>= 1.8, < 3)
|
180
146
|
simplecov-html (~> 0.10.0)
|
181
147
|
simplecov-html (0.10.2)
|
182
|
-
sprockets (3.7.
|
148
|
+
sprockets (3.7.2)
|
183
149
|
concurrent-ruby (~> 1.0)
|
184
150
|
rack (> 1, < 3)
|
185
|
-
sprockets-rails (3.2.
|
151
|
+
sprockets-rails (3.2.2)
|
186
152
|
actionpack (>= 4.0)
|
187
153
|
activesupport (>= 4.0)
|
188
154
|
sprockets (>= 3.0.0)
|
@@ -194,9 +160,9 @@ GEM
|
|
194
160
|
tins (1.16.3)
|
195
161
|
tzinfo (1.2.5)
|
196
162
|
thread_safe (~> 0.1)
|
197
|
-
websocket-driver (0.7.
|
163
|
+
websocket-driver (0.7.3)
|
198
164
|
websocket-extensions (>= 0.1.0)
|
199
|
-
websocket-extensions (0.1.
|
165
|
+
websocket-extensions (0.1.5)
|
200
166
|
|
201
167
|
PLATFORMS
|
202
168
|
ruby
|
@@ -205,11 +171,10 @@ DEPENDENCIES
|
|
205
171
|
active_job_log!
|
206
172
|
coveralls
|
207
173
|
factory_bot_rails
|
208
|
-
guard-rspec
|
209
174
|
pry
|
210
175
|
pry-rails
|
211
176
|
rspec-rails
|
212
177
|
sqlite3
|
213
178
|
|
214
179
|
BUNDLED WITH
|
215
|
-
1.
|
180
|
+
2.1.4
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Active Job Log
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/active_job_log.svg)](https://badge.fury.io/rb/active_job_log)
|
4
|
+
[![Build Status](https://travis-ci.org/platanus/active_job_log.svg?branch=master)](https://travis-ci.org/platanus/active_job_log)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/github/platanus/active_job_log/badge.svg?branch=master)](https://coveralls.io/github/platanus/active_job_log?branch=master)
|
6
|
+
|
3
7
|
Rails engine to register jobs history, adding: job state, error feedback, duration, etc.
|
4
8
|
|
5
9
|
## Installation
|
data/active_job_log.gemspec
CHANGED
@@ -26,7 +26,6 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_development_dependency "pry-rails"
|
27
27
|
s.add_development_dependency "sqlite3"
|
28
28
|
s.add_development_dependency "rspec-rails"
|
29
|
-
s.add_development_dependency "guard-rspec"
|
30
29
|
s.add_development_dependency "factory_bot_rails"
|
31
30
|
s.add_development_dependency "coveralls"
|
32
31
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module ActiveJobLog
|
2
|
+
module Loggeable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
extend Enumerize
|
7
|
+
|
8
|
+
STATUSES = %i{queued pending finished failed}
|
9
|
+
|
10
|
+
validates :job_id, presence: true
|
11
|
+
|
12
|
+
enumerize :status, in: STATUSES, scope: true
|
13
|
+
|
14
|
+
serialize :params, Array
|
15
|
+
serialize :stack_trace, Array
|
16
|
+
|
17
|
+
before_save :set_queued_duration
|
18
|
+
before_save :set_execution_duration
|
19
|
+
before_save :set_total_duration
|
20
|
+
|
21
|
+
def set_queued_duration
|
22
|
+
return if queued_at.blank? || started_at.blank?
|
23
|
+
self.queued_duration = (started_at.to_f - queued_at.to_f).to_i
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_execution_duration
|
27
|
+
return if started_at.blank? || ended_at.blank?
|
28
|
+
self.execution_duration = (ended_at.to_f - started_at.to_f).to_i
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_total_duration
|
32
|
+
from = queued_at || started_at
|
33
|
+
return if from.blank? || ended_at.blank?
|
34
|
+
self.total_duration = (ended_at.to_f - from.to_f).to_i
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module ClassMethods
|
39
|
+
def update_job!(job_id, status, params = {})
|
40
|
+
params.merge!(status_to_params(status))
|
41
|
+
job = find_or_create_job(job_id)
|
42
|
+
job.update!(params)
|
43
|
+
job
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_or_create_job(job_id)
|
47
|
+
where(job_id: job_id).where.not(status: :failed).last || create(job_id: job_id)
|
48
|
+
end
|
49
|
+
|
50
|
+
def status_to_params(status)
|
51
|
+
time_attr = infer_duration_attr_from_status(status)
|
52
|
+
{
|
53
|
+
time_attr => DateTime.current,
|
54
|
+
status: status
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def infer_duration_attr_from_status(status)
|
59
|
+
case status
|
60
|
+
when :queued
|
61
|
+
:queued_at
|
62
|
+
when :pending
|
63
|
+
:started_at
|
64
|
+
when :finished, :failed
|
65
|
+
:ended_at
|
66
|
+
else
|
67
|
+
fail "invalid status"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -117,71 +117,62 @@ RSpec.describe ActiveJobLog::Job, type: :model do
|
|
117
117
|
|
118
118
|
describe "#update_job!" do
|
119
119
|
let(:job_id) { "x" }
|
120
|
-
let(:
|
121
|
-
let(:perform) { described_class.update_job!(job_id, status, params) }
|
120
|
+
let(:params) { {} }
|
122
121
|
|
123
|
-
|
124
|
-
|
125
|
-
params: [1],
|
126
|
-
stack_trace: [2],
|
127
|
-
error: "error",
|
128
|
-
job_class: "MyJob"
|
129
|
-
}
|
122
|
+
def perform(status)
|
123
|
+
described_class.update_job!(job_id, status, params)
|
130
124
|
end
|
131
125
|
|
132
|
-
|
126
|
+
context "with params" do
|
127
|
+
let(:params) do
|
128
|
+
{
|
129
|
+
params: [1],
|
130
|
+
stack_trace: [2],
|
131
|
+
error: "error",
|
132
|
+
job_class: "MyJob"
|
133
|
+
}
|
134
|
+
end
|
133
135
|
|
134
|
-
|
135
|
-
let!(:job) { create(:active_job_log_job, job_id: job_id) }
|
136
|
-
|
137
|
-
it { expect { perform }.not_to change(ActiveJobLog::Job, :count) }
|
138
|
-
end
|
139
|
-
|
140
|
-
context "with queued status" do
|
141
|
-
before { @job = perform }
|
136
|
+
before { @job = perform(:queued) }
|
142
137
|
|
143
138
|
it { expect(@job.job_id).to eq(job_id) }
|
144
139
|
it { expect(@job.error).to eq("error") }
|
145
140
|
it { expect(@job.params).to eq([1]) }
|
146
141
|
it { expect(@job.stack_trace).to eq([2]) }
|
147
142
|
it { expect(@job.job_class).to eq("MyJob") }
|
143
|
+
end
|
144
|
+
|
145
|
+
context "with queued status" do
|
146
|
+
before { @job = perform(:queued) }
|
147
|
+
|
148
148
|
it { expect(@job.status).to eq(:queued) }
|
149
149
|
it { expect(@job.queued_at).not_to be_nil }
|
150
|
-
it { expect(
|
151
|
-
it { expect(@job.ended_at).to be_nil }
|
150
|
+
it { expect { perform(:pending) }.not_to change(described_class, :count) }
|
152
151
|
end
|
153
152
|
|
154
153
|
context "with pending status" do
|
155
|
-
|
156
|
-
|
157
|
-
before { @job = perform }
|
154
|
+
before { @job = perform(:pending) }
|
158
155
|
|
159
156
|
it { expect(@job.status).to eq(:pending) }
|
160
|
-
it { expect(@job.queued_at).to be_nil }
|
161
157
|
it { expect(@job.started_at).not_to be_nil }
|
162
|
-
it { expect(
|
158
|
+
it { expect { perform(:failed) }.not_to change(described_class, :count) }
|
159
|
+
it { expect { perform(:finished) }.not_to change(described_class, :count) }
|
163
160
|
end
|
164
161
|
|
165
162
|
context "with finished status" do
|
166
|
-
|
167
|
-
|
168
|
-
before { @job = perform }
|
163
|
+
before { @job = perform(:finished) }
|
169
164
|
|
170
165
|
it { expect(@job.status).to eq(:finished) }
|
171
|
-
it { expect(@job.queued_at).to be_nil }
|
172
|
-
it { expect(@job.started_at).to be_nil }
|
173
166
|
it { expect(@job.ended_at).not_to be_nil }
|
174
167
|
end
|
175
168
|
|
176
169
|
context "with failed status" do
|
177
|
-
|
178
|
-
|
179
|
-
before { @job = perform }
|
170
|
+
before { @job = perform(:failed) }
|
180
171
|
|
181
172
|
it { expect(@job.status).to eq(:failed) }
|
182
|
-
it { expect(@job.queued_at).to be_nil }
|
183
|
-
it { expect(@job.started_at).to be_nil }
|
184
173
|
it { expect(@job.ended_at).not_to be_nil }
|
174
|
+
it { expect { perform(:queued) }.to change(described_class, :count).from(1).to(2) }
|
175
|
+
it { expect { perform(:pending) }.to change(described_class, :count).from(1).to(2) }
|
185
176
|
end
|
186
177
|
end
|
187
178
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_job_log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Platanus
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -95,20 +95,6 @@ dependencies:
|
|
95
95
|
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
|
-
- !ruby/object:Gem::Dependency
|
99
|
-
name: guard-rspec
|
100
|
-
requirement: !ruby/object:Gem::Requirement
|
101
|
-
requirements:
|
102
|
-
- - ">="
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
version: '0'
|
105
|
-
type: :development
|
106
|
-
prerelease: false
|
107
|
-
version_requirements: !ruby/object:Gem::Requirement
|
108
|
-
requirements:
|
109
|
-
- - ">="
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
version: '0'
|
112
98
|
- !ruby/object:Gem::Dependency
|
113
99
|
name: factory_bot_rails
|
114
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,7 +156,6 @@ files:
|
|
170
156
|
- app/jobs/active_job_log/application_job.rb
|
171
157
|
- app/mailers/active_job_log/application_mailer.rb
|
172
158
|
- app/models/active_job_log/application_record.rb
|
173
|
-
- app/models/active_job_log/job.rb
|
174
159
|
- app/views/layouts/active_job_log/application.html.erb
|
175
160
|
- bin/rails
|
176
161
|
- config/routes.rb
|
@@ -178,10 +163,12 @@ files:
|
|
178
163
|
- lib/active_job_log.rb
|
179
164
|
- lib/active_job_log/engine.rb
|
180
165
|
- lib/active_job_log/log_ext.rb
|
166
|
+
- lib/active_job_log/loggeable.rb
|
181
167
|
- lib/active_job_log/version.rb
|
182
168
|
- lib/generators/active_job_log/install/USAGE
|
183
169
|
- lib/generators/active_job_log/install/install_generator.rb
|
184
170
|
- lib/generators/active_job_log/install/templates/initializer.rb
|
171
|
+
- lib/generators/active_job_log/install/templates/job_model.rb
|
185
172
|
- lib/tasks/active_job_log_tasks.rake
|
186
173
|
- spec/dummy/Rakefile
|
187
174
|
- spec/dummy/app/assets/config/manifest.js
|
@@ -194,6 +181,7 @@ files:
|
|
194
181
|
- spec/dummy/app/helpers/application_helper.rb
|
195
182
|
- spec/dummy/app/jobs/application_job.rb
|
196
183
|
- spec/dummy/app/mailers/application_mailer.rb
|
184
|
+
- spec/dummy/app/models/active_job_log/job.rb
|
197
185
|
- spec/dummy/app/models/application_record.rb
|
198
186
|
- spec/dummy/app/views/layouts/application.html.erb
|
199
187
|
- spec/dummy/app/views/layouts/mailer.html.erb
|
@@ -261,68 +249,68 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
261
249
|
- !ruby/object:Gem::Version
|
262
250
|
version: '0'
|
263
251
|
requirements: []
|
264
|
-
|
265
|
-
rubygems_version: 2.7.7
|
252
|
+
rubygems_version: 3.0.8
|
266
253
|
signing_key:
|
267
254
|
specification_version: 4
|
268
255
|
summary: Rails engine to keep jobs history
|
269
256
|
test_files:
|
270
|
-
- spec/
|
271
|
-
- spec/dummy/app/
|
257
|
+
- spec/spec_helper.rb
|
258
|
+
- spec/dummy/app/mailers/application_mailer.rb
|
259
|
+
- spec/dummy/app/channels/application_cable/connection.rb
|
260
|
+
- spec/dummy/app/channels/application_cable/channel.rb
|
261
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
262
|
+
- spec/dummy/app/views/layouts/mailer.text.erb
|
263
|
+
- spec/dummy/app/views/layouts/mailer.html.erb
|
264
|
+
- spec/dummy/app/jobs/application_job.rb
|
265
|
+
- spec/dummy/app/models/application_record.rb
|
266
|
+
- spec/dummy/app/models/active_job_log/job.rb
|
267
|
+
- spec/dummy/app/helpers/application_helper.rb
|
272
268
|
- spec/dummy/app/assets/javascripts/application.js
|
273
269
|
- spec/dummy/app/assets/javascripts/cable.js
|
274
270
|
- spec/dummy/app/assets/stylesheets/application.css
|
275
|
-
- spec/dummy/app/
|
276
|
-
- spec/dummy/app/channels/application_cable/connection.rb
|
271
|
+
- spec/dummy/app/assets/config/manifest.js
|
277
272
|
- spec/dummy/app/controllers/application_controller.rb
|
278
|
-
- spec/dummy/
|
279
|
-
- spec/dummy/
|
280
|
-
- spec/dummy/
|
281
|
-
- spec/dummy/
|
282
|
-
- spec/dummy/app/views/layouts/application.html.erb
|
283
|
-
- spec/dummy/app/views/layouts/mailer.html.erb
|
284
|
-
- spec/dummy/app/views/layouts/mailer.text.erb
|
273
|
+
- spec/dummy/Rakefile
|
274
|
+
- spec/dummy/bin/yarn
|
275
|
+
- spec/dummy/bin/update
|
276
|
+
- spec/dummy/bin/rake
|
285
277
|
- spec/dummy/bin/bundle
|
286
278
|
- spec/dummy/bin/rails
|
287
|
-
- spec/dummy/bin/rake
|
288
279
|
- spec/dummy/bin/setup
|
289
|
-
- spec/dummy/
|
290
|
-
- spec/dummy/
|
280
|
+
- spec/dummy/spec/support/test_helpers.rb
|
281
|
+
- spec/dummy/spec/assets/image.png
|
282
|
+
- spec/dummy/spec/assets/video.mp4
|
283
|
+
- spec/dummy/public/404.html
|
284
|
+
- spec/dummy/public/500.html
|
285
|
+
- spec/dummy/public/apple-touch-icon-precomposed.png
|
286
|
+
- spec/dummy/public/422.html
|
287
|
+
- spec/dummy/public/apple-touch-icon.png
|
288
|
+
- spec/dummy/public/favicon.ico
|
291
289
|
- spec/dummy/config.ru
|
290
|
+
- spec/dummy/db/schema.rb
|
291
|
+
- spec/dummy/config/routes.rb
|
292
|
+
- spec/dummy/config/environment.rb
|
293
|
+
- spec/dummy/config/spring.rb
|
294
|
+
- spec/dummy/config/cable.yml
|
295
|
+
- spec/dummy/config/secrets.yml
|
292
296
|
- spec/dummy/config/application.rb
|
293
297
|
- spec/dummy/config/boot.rb
|
294
|
-
- spec/dummy/config/
|
295
|
-
- spec/dummy/config/database.yml
|
296
|
-
- spec/dummy/config/environment.rb
|
298
|
+
- spec/dummy/config/environments/test.rb
|
297
299
|
- spec/dummy/config/environments/development.rb
|
298
300
|
- spec/dummy/config/environments/production.rb
|
299
|
-
- spec/dummy/config/environments/test.rb
|
300
|
-
- spec/dummy/config/initializers/application_controller_renderer.rb
|
301
|
-
- spec/dummy/config/initializers/assets.rb
|
302
|
-
- spec/dummy/config/initializers/backtrace_silencers.rb
|
303
|
-
- spec/dummy/config/initializers/cookies_serializer.rb
|
304
|
-
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
305
|
-
- spec/dummy/config/initializers/inflections.rb
|
306
|
-
- spec/dummy/config/initializers/mime_types.rb
|
307
|
-
- spec/dummy/config/initializers/wrap_parameters.rb
|
308
301
|
- spec/dummy/config/locales/en.yml
|
309
302
|
- spec/dummy/config/puma.rb
|
310
|
-
- spec/dummy/config/
|
311
|
-
- spec/dummy/config/
|
312
|
-
- spec/dummy/config/
|
313
|
-
- spec/dummy/
|
303
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
304
|
+
- spec/dummy/config/initializers/mime_types.rb
|
305
|
+
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
306
|
+
- spec/dummy/config/initializers/assets.rb
|
307
|
+
- spec/dummy/config/initializers/application_controller_renderer.rb
|
308
|
+
- spec/dummy/config/initializers/inflections.rb
|
309
|
+
- spec/dummy/config/initializers/cookies_serializer.rb
|
310
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
311
|
+
- spec/dummy/config/database.yml
|
314
312
|
- spec/dummy/package.json
|
315
|
-
- spec/dummy/public/404.html
|
316
|
-
- spec/dummy/public/422.html
|
317
|
-
- spec/dummy/public/500.html
|
318
|
-
- spec/dummy/public/apple-touch-icon-precomposed.png
|
319
|
-
- spec/dummy/public/apple-touch-icon.png
|
320
|
-
- spec/dummy/public/favicon.ico
|
321
|
-
- spec/dummy/spec/assets/image.png
|
322
|
-
- spec/dummy/spec/assets/video.mp4
|
323
|
-
- spec/dummy/spec/support/test_helpers.rb
|
324
|
-
- spec/factories/active_job_log_jobs.rb
|
325
313
|
- spec/lib/active_job_log/log_ext_spec.rb
|
326
314
|
- spec/models/active_job_log/job_spec.rb
|
315
|
+
- spec/factories/active_job_log_jobs.rb
|
327
316
|
- spec/rails_helper.rb
|
328
|
-
- spec/spec_helper.rb
|
@@ -1,68 +0,0 @@
|
|
1
|
-
module ActiveJobLog
|
2
|
-
class Job < ApplicationRecord
|
3
|
-
extend Enumerize
|
4
|
-
|
5
|
-
STATUSES = %i{queued pending finished failed}
|
6
|
-
|
7
|
-
validates :job_id, presence: true
|
8
|
-
|
9
|
-
enumerize :status, in: STATUSES, scope: true
|
10
|
-
|
11
|
-
serialize :params, Array
|
12
|
-
serialize :stack_trace, Array
|
13
|
-
|
14
|
-
before_save :set_queued_duration
|
15
|
-
before_save :set_execution_duration
|
16
|
-
before_save :set_total_duration
|
17
|
-
|
18
|
-
def self.update_job!(job_id, status, params = {})
|
19
|
-
params.merge!(status_to_params(status))
|
20
|
-
job = Job.find_or_create_by(job_id: job_id)
|
21
|
-
job.update_attributes!(params)
|
22
|
-
job
|
23
|
-
end
|
24
|
-
|
25
|
-
class << self
|
26
|
-
private
|
27
|
-
|
28
|
-
def status_to_params(status)
|
29
|
-
time_attr = infer_duration_attr_from_status(status)
|
30
|
-
{
|
31
|
-
time_attr => DateTime.current,
|
32
|
-
status: status
|
33
|
-
}
|
34
|
-
end
|
35
|
-
|
36
|
-
def infer_duration_attr_from_status(status)
|
37
|
-
case status
|
38
|
-
when :queued
|
39
|
-
:queued_at
|
40
|
-
when :pending
|
41
|
-
:started_at
|
42
|
-
when :finished, :failed
|
43
|
-
:ended_at
|
44
|
-
else
|
45
|
-
fail "invalid status"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def set_queued_duration
|
53
|
-
return if queued_at.blank? || started_at.blank?
|
54
|
-
self.queued_duration = (started_at.to_f - queued_at.to_f).to_i
|
55
|
-
end
|
56
|
-
|
57
|
-
def set_execution_duration
|
58
|
-
return if started_at.blank? || ended_at.blank?
|
59
|
-
self.execution_duration = (ended_at.to_f - started_at.to_f).to_i
|
60
|
-
end
|
61
|
-
|
62
|
-
def set_total_duration
|
63
|
-
from = queued_at || started_at
|
64
|
-
return if from.blank? || ended_at.blank?
|
65
|
-
self.total_duration = (ended_at.to_f - from.to_f).to_i
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|