logging_worker 0.3.0 → 0.3.1

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: db4ba954cf6bbd1641c36fb30a943145728ffe4c
4
- data.tar.gz: 53c8b58c918317b7414927b05656c47d17f47cc3
3
+ metadata.gz: cee20c47d414820e4304760caf55d2cf166844cd
4
+ data.tar.gz: 7cc1fc4d0e0dcae4adc8e714d84a92905727180f
5
5
  SHA512:
6
- metadata.gz: 9130117d5dfe30aaecd34c60c4e377e35fda12591356009a23d6d739cf1fa4b63474ee7dd730417bdc0e90181be312c564f3ddaed1f294e98a4441331c68980e
7
- data.tar.gz: e903262551220f97af34e8a57f5c70c3313af5c18119a0e0953fc0164a0d9d07f11bfa87646f082506b4f22102512086c664d0a776ba29d6189f7d95f41a0cb5
6
+ metadata.gz: 69f459050404932c790158e123c2e82b90b54cf6a573a2331d7f6c3cba3bfabdc4b247a87e8caad9bb17fe7711f40e82648d4ef1fb2ebe125708e8b97fd35ef8
7
+ data.tar.gz: f7d394a448b46448e1cd43b427b6ea14ce3b4fce7e58aac340a28d5b5765750ef6b49da033cee46362b0cf1d02977a2ccde9c42a571a3b4e29d589e53373c579
@@ -5,12 +5,19 @@ class LoggingWorker::JobRun < ApplicationRecord
5
5
  end
6
6
 
7
7
  def logger
8
- @logger ||= Logger.new(StringIO.new(log))
8
+ @io ||= StringIO.new
9
+ @logger ||= Logger.new(@io)
9
10
  end
10
11
 
11
- def flush_log!
12
- log_will_change!
13
- save!
12
+ def flush_log!(save_to_db = true)
13
+ @io.rewind
14
+ content = @io.read
15
+ self.log += content
16
+ save! if save_to_db
17
+ @io.close
18
+ @logger.close
19
+ @io = nil
20
+ @logger = nil
14
21
  end
15
22
 
16
23
  def do_not_record!
@@ -27,6 +34,8 @@ class LoggingWorker::JobRun < ApplicationRecord
27
34
  else
28
35
  self.successful = false if successful.nil?
29
36
  self.completed_at = Time.now
37
+ logger # make sure we've got it
38
+ flush_log!(false)
30
39
  save!
31
40
  end
32
41
  end
@@ -1,3 +1,3 @@
1
1
  module LoggingWorker
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -19,8 +19,6 @@ module LoggingWorker
19
19
  job_run.arguments = args
20
20
  job_run.save!
21
21
 
22
- job_run.log_will_change!
23
-
24
22
  super
25
23
 
26
24
  job_run.successful!
@@ -10,6 +10,7 @@ describe JobRun do
10
10
  specify "logging during the run" do
11
11
  job_run = JobRun.new
12
12
  job_run.logger.info("test")
13
+ job_run.flush_log!
13
14
  expect(job_run.log).to include("test")
14
15
  end
15
16
  end
@@ -79,9 +79,11 @@ describe LoggingWorker::Worker do
79
79
  run.flush_log!
80
80
  expect(LoggingWorker::JobRun.first.log).to include("Test this")
81
81
  expect(LoggingWorker::JobRun.first.log).to include("Testing more")
82
+ run.logger.info "Testing even more"
82
83
  run.completed!
83
84
  expect(LoggingWorker::JobRun.first.log).to include("Test this")
84
85
  expect(LoggingWorker::JobRun.first.log).to include("Testing more")
86
+ expect(LoggingWorker::JobRun.first.log).to include("Testing even more")
85
87
  end
86
88
 
87
89
  specify "self desctruct on complete" do
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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Oestrich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-08 00:00:00.000000000 Z
11
+ date: 2018-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails