logging_worker 0.2.0 → 0.3.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/app/models/logging_worker/job_run.rb +17 -3
- data/lib/logging_worker/version.rb +1 -1
- data/spec/worker_spec.rb +25 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db4ba954cf6bbd1641c36fb30a943145728ffe4c
|
4
|
+
data.tar.gz: 53c8b58c918317b7414927b05656c47d17f47cc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9130117d5dfe30aaecd34c60c4e377e35fda12591356009a23d6d739cf1fa4b63474ee7dd730417bdc0e90181be312c564f3ddaed1f294e98a4441331c68980e
|
7
|
+
data.tar.gz: e903262551220f97af34e8a57f5c70c3313af5c18119a0e0953fc0164a0d9d07f11bfa87646f082506b4f22102512086c664d0a776ba29d6189f7d95f41a0cb5
|
@@ -1,19 +1,33 @@
|
|
1
1
|
class LoggingWorker::JobRun < ApplicationRecord
|
2
2
|
after_initialize do
|
3
3
|
self[:log] ||= ""
|
4
|
+
@do_not_record = false
|
4
5
|
end
|
5
6
|
|
6
7
|
def logger
|
7
8
|
@logger ||= Logger.new(StringIO.new(log))
|
8
9
|
end
|
9
10
|
|
11
|
+
def flush_log!
|
12
|
+
log_will_change!
|
13
|
+
save!
|
14
|
+
end
|
15
|
+
|
16
|
+
def do_not_record!
|
17
|
+
@do_not_record = true
|
18
|
+
end
|
19
|
+
|
10
20
|
def successful!
|
11
21
|
self.successful = true
|
12
22
|
end
|
13
23
|
|
14
24
|
def completed!
|
15
|
-
|
16
|
-
|
17
|
-
|
25
|
+
if @do_not_record
|
26
|
+
destroy!
|
27
|
+
else
|
28
|
+
self.successful = false if successful.nil?
|
29
|
+
self.completed_at = Time.now
|
30
|
+
save!
|
31
|
+
end
|
18
32
|
end
|
19
33
|
end
|
data/spec/worker_spec.rb
CHANGED
@@ -68,4 +68,29 @@ describe LoggingWorker::Worker do
|
|
68
68
|
new_job_run_worker.perform
|
69
69
|
expect(new_job_run_worker.job_run).to be_a(::JobRun)
|
70
70
|
end
|
71
|
+
|
72
|
+
specify "allow the flush of a log" do
|
73
|
+
run = LoggingWorker::JobRun.create
|
74
|
+
run.logger.info "Test this"
|
75
|
+
expect(LoggingWorker::JobRun.first.log).to eq("")
|
76
|
+
run.flush_log!
|
77
|
+
expect(LoggingWorker::JobRun.first.log).to include("Test this")
|
78
|
+
run.logger.info "Testing more"
|
79
|
+
run.flush_log!
|
80
|
+
expect(LoggingWorker::JobRun.first.log).to include("Test this")
|
81
|
+
expect(LoggingWorker::JobRun.first.log).to include("Testing more")
|
82
|
+
run.completed!
|
83
|
+
expect(LoggingWorker::JobRun.first.log).to include("Test this")
|
84
|
+
expect(LoggingWorker::JobRun.first.log).to include("Testing more")
|
85
|
+
end
|
86
|
+
|
87
|
+
specify "self desctruct on complete" do
|
88
|
+
run = LoggingWorker::JobRun.create
|
89
|
+
run.do_not_record!
|
90
|
+
expect {
|
91
|
+
run.completed!
|
92
|
+
}.to change {
|
93
|
+
LoggingWorker::JobRun.count
|
94
|
+
}.by(-1)
|
95
|
+
end
|
71
96
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logging_worker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Oestrich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|