active_job_log 0.2.1 → 1.0.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: 631bb4927c7b983aa4769085de0462843e127bf9ee68e4f7525b8faa1cf6d594
4
- data.tar.gz: 418431e2de9e9ab94f82ff3c8eca48062178b53aa52261924a4056350aab4208
3
+ metadata.gz: bfbf0127bae9efde3b2c7e9ea25b1673a045efed6d6c27ffd9e41b3bf99722c6
4
+ data.tar.gz: b5443486b6e699d85b0cf37ac08bebabe58d520660b6fa377fde7065ae063a45
5
5
  SHA512:
6
- metadata.gz: 0c0874d42b2a885d261813412fb3b719746cf8d7c620fd5337736e038960ec9a919743cd7a70cfe92a059a10d706d49f73a0d1e5871978201ae69414eebb2a32
7
- data.tar.gz: 8f23eb67fadd5abcfc0289f74d1f35ae0a9a72ab025f9f23db11e27915efa9dbcd9d722edea1e9adc2f575a8c7a08b2b8889981d70c3f4305f0ca3691da12ea9
6
+ metadata.gz: 9c5dd6c2715bb55d4ce6168da27e801a2ddd70afe1a930a269e577778b6952ef2b5087d173ac4dd648a30db062164af99d99c5331904a85c4b59caedba3555ae
7
+ data.tar.gz: 5419a4c87f8b82b5cdf3928009d265aa84c69852a00dc2cbe5fd21b75f27fa348428ee7a8ffb2c4f153482b2afa44fc917dc016ef2690de6e831e7dde12a342a
@@ -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
+ ### v1.0.0
6
+
7
+ #### Changed
8
+
9
+ * Copy Job model into app.
10
+
5
11
  ### v0.2.1
6
12
 
7
13
  #### Fixed
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_job_log (0.2.1)
4
+ active_job_log (1.0.0)
5
5
  enumerize (>= 1.0)
6
6
  rails (>= 4.2.0)
7
7
 
@@ -99,7 +99,7 @@ GEM
99
99
  crass (~> 1.0.2)
100
100
  nokogiri (>= 1.5.9)
101
101
  lumberjack (1.0.13)
102
- mail (2.7.0)
102
+ mail (2.7.1)
103
103
  mini_mime (>= 0.1.1)
104
104
  marcel (0.3.3)
105
105
  mimemagic (~> 0.3.2)
@@ -9,6 +9,7 @@ module ActiveJobLog
9
9
 
10
10
  initializer "initialize" do
11
11
  require_relative "./log_ext"
12
+ require_relative "./loggeable"
12
13
  end
13
14
  end
14
15
  end
@@ -0,0 +1,72 @@
1
+ module ActiveJobLog
2
+ module Loggeable
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ extend Enumerize
7
+
8
+ STATUSES = %i{queued pending finished failed}
9
+
10
+ validates :job_id, presence: true
11
+
12
+ enumerize :status, in: STATUSES, scope: true
13
+
14
+ serialize :params, Array
15
+ serialize :stack_trace, Array
16
+
17
+ before_save :set_queued_duration
18
+ before_save :set_execution_duration
19
+ before_save :set_total_duration
20
+
21
+ def set_queued_duration
22
+ return if queued_at.blank? || started_at.blank?
23
+ self.queued_duration = (started_at.to_f - queued_at.to_f).to_i
24
+ end
25
+
26
+ def set_execution_duration
27
+ return if started_at.blank? || ended_at.blank?
28
+ self.execution_duration = (ended_at.to_f - started_at.to_f).to_i
29
+ end
30
+
31
+ def set_total_duration
32
+ from = queued_at || started_at
33
+ return if from.blank? || ended_at.blank?
34
+ self.total_duration = (ended_at.to_f - from.to_f).to_i
35
+ end
36
+ end
37
+
38
+ module ClassMethods
39
+ def update_job!(job_id, status, params = {})
40
+ params.merge!(status_to_params(status))
41
+ job = find_or_create_job(job_id)
42
+ job.update_attributes!(params)
43
+ job
44
+ end
45
+
46
+ def find_or_create_job(job_id)
47
+ where(job_id: job_id).where.not(status: :failed).last || create(job_id: job_id)
48
+ end
49
+
50
+ def status_to_params(status)
51
+ time_attr = infer_duration_attr_from_status(status)
52
+ {
53
+ time_attr => DateTime.current,
54
+ status: status
55
+ }
56
+ end
57
+
58
+ def infer_duration_attr_from_status(status)
59
+ case status
60
+ when :queued
61
+ :queued_at
62
+ when :pending
63
+ :started_at
64
+ when :finished, :failed
65
+ :ended_at
66
+ else
67
+ fail "invalid status"
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveJobLog
2
- VERSION = '0.2.1'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -13,6 +13,10 @@ class ActiveJobLog::InstallGenerator < Rails::Generators::Base
13
13
  end
14
14
  end
15
15
 
16
+ def copy_job_model
17
+ copy_file "job_model.rb", "app/models/active_job_log/job.rb"
18
+ end
19
+
16
20
  def copy_engine_migrations
17
21
  rake "railties:install:migrations"
18
22
  end
@@ -0,0 +1,5 @@
1
+ module ActiveJobLog
2
+ class Job < ApplicationRecord
3
+ include Loggeable
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveJobLog
2
+ class Job < ApplicationRecord
3
+ include Loggeable
4
+ end
5
+ 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.2.1
4
+ version: 1.0.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-10-12 00:00:00.000000000 Z
12
+ date: 2018-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -170,7 +170,6 @@ files:
170
170
  - app/jobs/active_job_log/application_job.rb
171
171
  - app/mailers/active_job_log/application_mailer.rb
172
172
  - app/models/active_job_log/application_record.rb
173
- - app/models/active_job_log/job.rb
174
173
  - app/views/layouts/active_job_log/application.html.erb
175
174
  - bin/rails
176
175
  - config/routes.rb
@@ -178,10 +177,12 @@ files:
178
177
  - lib/active_job_log.rb
179
178
  - lib/active_job_log/engine.rb
180
179
  - lib/active_job_log/log_ext.rb
180
+ - lib/active_job_log/loggeable.rb
181
181
  - lib/active_job_log/version.rb
182
182
  - lib/generators/active_job_log/install/USAGE
183
183
  - lib/generators/active_job_log/install/install_generator.rb
184
184
  - lib/generators/active_job_log/install/templates/initializer.rb
185
+ - lib/generators/active_job_log/install/templates/job_model.rb
185
186
  - lib/tasks/active_job_log_tasks.rake
186
187
  - spec/dummy/Rakefile
187
188
  - spec/dummy/app/assets/config/manifest.js
@@ -194,6 +195,7 @@ files:
194
195
  - spec/dummy/app/helpers/application_helper.rb
195
196
  - spec/dummy/app/jobs/application_job.rb
196
197
  - spec/dummy/app/mailers/application_mailer.rb
198
+ - spec/dummy/app/models/active_job_log/job.rb
197
199
  - spec/dummy/app/models/application_record.rb
198
200
  - spec/dummy/app/views/layouts/application.html.erb
199
201
  - spec/dummy/app/views/layouts/mailer.html.erb
@@ -262,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
264
  version: '0'
263
265
  requirements: []
264
266
  rubyforge_project:
265
- rubygems_version: 2.7.7
267
+ rubygems_version: 2.7.8
266
268
  signing_key:
267
269
  specification_version: 4
268
270
  summary: Rails engine to keep jobs history
@@ -278,6 +280,7 @@ test_files:
278
280
  - spec/dummy/app/helpers/application_helper.rb
279
281
  - spec/dummy/app/jobs/application_job.rb
280
282
  - spec/dummy/app/mailers/application_mailer.rb
283
+ - spec/dummy/app/models/active_job_log/job.rb
281
284
  - spec/dummy/app/models/application_record.rb
282
285
  - spec/dummy/app/views/layouts/application.html.erb
283
286
  - spec/dummy/app/views/layouts/mailer.html.erb
@@ -1,72 +0,0 @@
1
- module ActiveJobLog
2
- class Job < ApplicationRecord
3
- extend Enumerize
4
-
5
- STATUSES = %i{queued pending finished failed}
6
-
7
- validates :job_id, presence: true
8
-
9
- enumerize :status, in: STATUSES, scope: true
10
-
11
- serialize :params, Array
12
- serialize :stack_trace, Array
13
-
14
- before_save :set_queued_duration
15
- before_save :set_execution_duration
16
- before_save :set_total_duration
17
-
18
- def self.update_job!(job_id, status, params = {})
19
- params.merge!(status_to_params(status))
20
- job = find_or_create_job(job_id)
21
- job.update_attributes!(params)
22
- job
23
- end
24
-
25
- class << self
26
- private
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
-
32
- def status_to_params(status)
33
- time_attr = infer_duration_attr_from_status(status)
34
- {
35
- time_attr => DateTime.current,
36
- status: status
37
- }
38
- end
39
-
40
- def infer_duration_attr_from_status(status)
41
- case status
42
- when :queued
43
- :queued_at
44
- when :pending
45
- :started_at
46
- when :finished, :failed
47
- :ended_at
48
- else
49
- fail "invalid status"
50
- end
51
- end
52
- end
53
-
54
- private
55
-
56
- def set_queued_duration
57
- return if queued_at.blank? || started_at.blank?
58
- self.queued_duration = (started_at.to_f - queued_at.to_f).to_i
59
- end
60
-
61
- def set_execution_duration
62
- return if started_at.blank? || ended_at.blank?
63
- self.execution_duration = (ended_at.to_f - started_at.to_f).to_i
64
- end
65
-
66
- def set_total_duration
67
- from = queued_at || started_at
68
- return if from.blank? || ended_at.blank?
69
- self.total_duration = (ended_at.to_f - from.to_f).to_i
70
- end
71
- end
72
- end