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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 885892cec8f03e18212d7007f1c68a7e0d4afa88138d2b43b022108e7c21d362
4
- data.tar.gz: a636f27b11735eb31fcbff1646179fdc3ffa7e800bdfead02d1901b4f87e5bc1
3
+ metadata.gz: 5def13eb7b203c3386c901d816f013bcd862adc49c3bfa0cf29771fc57b2e676
4
+ data.tar.gz: 0cdf2baf1a11a9e1df69f69a785f0268a28c1db42b633d6f30e4043502847a93
5
5
  SHA512:
6
- metadata.gz: daa6aa8c8ac55e37a0d598f271e33e21d942b13d2cdebb0565f73e3d7f4a97be27deb8edd077152480835e5c75b565c98d04f2b650631479510865ee7637a52a
7
- data.tar.gz: 24dea753b7fce617c926fd3ea208d10ca3236a8ae2d14816cf210aeb737ccd332d214f28efab5f2b2c83de1334814a1742a0217667a4a474d94a23f503cfd010
6
+ metadata.gz: 7238509212fcc3cb8c972e5bd4979556ba942474dfa7ec0fe99f943e195ff7301cfc73e8965ae670c5b0ae719be99069ce1e2ddd07b201bc2f85703b1ddd757d
7
+ data.tar.gz: 07893eee397c648fc81b6db4bed16a9cfa7ab9bc8fa631d9438525c465ce2a645404a9852bac510785d9bc9224a424dbb25ae99153855ab8b9b9a2dcd10ed487
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
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
+ ### v0.2.0
6
+
7
+ #### Added
8
+
9
+ * New Job instance by retry.
10
+
5
11
  ### v0.1.0
6
12
 
7
13
  * Initial release.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_job_log (0.1.0)
4
+ active_job_log (0.2.0)
5
5
  enumerize (>= 1.0)
6
6
  rails (>= 4.2.0)
7
7
 
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 = Job.find_or_create_by(job_id: job_id)
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
  {
@@ -1,3 +1,3 @@
1
1
  module ActiveJobLog
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -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(:status) { :queued }
121
- let(:perform) { described_class.update_job!(job_id, status, params) }
120
+ let(:params) { {} }
122
121
 
123
- let(:params) do
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
- it { expect { perform }.to change(ActiveJobLog::Job, :count).from(0).to(1) }
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
- context "with existent job" do
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(@job.started_at).to be_nil }
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
- let(:status) { :pending }
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(@job.ended_at).to be_nil }
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
- let(:status) { :finished }
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
- let(:status) { :failed }
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.1.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-05-18 00:00:00.000000000 Z
12
+ date: 2018-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails