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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 465954f35a94ae7debcedebe1bc032f7f23d804d
4
- data.tar.gz: 54f92f51519aba4d8f8895f02e342dcbe355a96c
3
+ metadata.gz: db4ba954cf6bbd1641c36fb30a943145728ffe4c
4
+ data.tar.gz: 53c8b58c918317b7414927b05656c47d17f47cc3
5
5
  SHA512:
6
- metadata.gz: 63872fc0c31ee16e110cefd0d23ca18698be4d1534bc65cc9763cefcf49b11c5cc585487de226fc08980aaa1881698cdaa5d8e6b853eaacc2ec779b2f8711784
7
- data.tar.gz: 6fbf0c672dde6c465cfd0ec0218357bdcd4fba16bb3c99528c8f26273bbe7fd58acd94e2adb8f5e3dfc07689bd8b20e39466baf33636e68b6109fbadb758c8dc
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
- self.successful = false if successful.nil?
16
- self.completed_at = Time.now
17
- save!
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
@@ -1,3 +1,3 @@
1
1
  module LoggingWorker
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  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.2.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: 2017-06-30 00:00:00.000000000 Z
11
+ date: 2018-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails