active_job_log 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/app/models/active_job_log/job.rb +5 -1
- data/lib/active_job_log/version.rb +1 -1
- data/spec/models/active_job_log/job_spec.rb +26 -35
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5def13eb7b203c3386c901d816f013bcd862adc49c3bfa0cf29771fc57b2e676
|
4
|
+
data.tar.gz: 0cdf2baf1a11a9e1df69f69a785f0268a28c1db42b633d6f30e4043502847a93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7238509212fcc3cb8c972e5bd4979556ba942474dfa7ec0fe99f943e195ff7301cfc73e8965ae670c5b0ae719be99069ce1e2ddd07b201bc2f85703b1ddd757d
|
7
|
+
data.tar.gz: 07893eee397c648fc81b6db4bed16a9cfa7ab9bc8fa631d9438525c465ce2a645404a9852bac510785d9bc9224a424dbb25ae99153855ab8b9b9a2dcd10ed487
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
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
|
@@ -17,7 +17,7 @@ module ActiveJobLog
|
|
17
17
|
|
18
18
|
def self.update_job!(job_id, status, params = {})
|
19
19
|
params.merge!(status_to_params(status))
|
20
|
-
job =
|
20
|
+
job = find_or_create_job(job_id)
|
21
21
|
job.update_attributes!(params)
|
22
22
|
job
|
23
23
|
end
|
@@ -25,6 +25,10 @@ module ActiveJobLog
|
|
25
25
|
class << self
|
26
26
|
private
|
27
27
|
|
28
|
+
def find_or_create_job(job_id)
|
29
|
+
Job.where(job_id: job_id).where.not(status: :failed).last || Job.create(job_id: job_id)
|
30
|
+
end
|
31
|
+
|
28
32
|
def status_to_params(status)
|
29
33
|
time_attr = infer_duration_attr_from_status(status)
|
30
34
|
{
|
@@ -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: 0.
|
4
|
+
version: 0.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: 2018-
|
12
|
+
date: 2018-06-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|