activejob-status 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/activejob-status.rb +42 -0
- data/lib/activejob-status/progress.rb +44 -0
- data/lib/activejob-status/status.rb +46 -0
- data/lib/activejob-status/storage.rb +33 -0
- data/lib/activejob-status/version.rb +5 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 91270803a5d6aedcc62a941ff58924eacfc41b8c
|
4
|
+
data.tar.gz: a56e19cb1959a274fa10aff9094f02b60ab10e9a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75d8b48d03c42bc15d7c608d11bd304109215f020cde362c19708c3325b8f3789169c605c2b73ccab3c981ad950e9faa43aee0625c7d42f3a6060c5abd41d5e2
|
7
|
+
data.tar.gz: 2fa52788bbbab62b350ba48c10ac2fc5cc16fc11c68ef5149292fb2fcd3319f96886ec025888cea628fcd0c74f56e641a7b100db7f8db86889e6566a76bfffeb
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'activejob-status/storage'
|
2
|
+
require 'activejob-status/status'
|
3
|
+
require 'activejob-status/progress'
|
4
|
+
|
5
|
+
module ActiveJob::Status
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
DEFAULT_EXPIRY = 60 * 30
|
8
|
+
|
9
|
+
included do
|
10
|
+
before_enqueue {|job| job.status.update(status: :queued) }
|
11
|
+
before_perform {|job| job.status.update(status: :working) }
|
12
|
+
after_perform {|job| job.status.update(status: :completed) }
|
13
|
+
|
14
|
+
rescue_from(Exception) do |e|
|
15
|
+
self.status.update(status: :failed)
|
16
|
+
raise e
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def status
|
21
|
+
@status ||= Status.new(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def progress
|
25
|
+
@progress ||= Progress.new(self)
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def store= store
|
30
|
+
store = ActiveSupport::Cache.lookup_store(store) if store.is_a?(Symbol)
|
31
|
+
@@store = store
|
32
|
+
end
|
33
|
+
|
34
|
+
def store
|
35
|
+
@@store ||= (defined?(Rails) && Rails.cache)
|
36
|
+
end
|
37
|
+
|
38
|
+
def get(id)
|
39
|
+
Status.new(id)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ActiveJob::Status
|
2
|
+
class Progress
|
3
|
+
delegate :[], :to_s, :inspect, to: :hash
|
4
|
+
|
5
|
+
def initialize(job)
|
6
|
+
@job = job
|
7
|
+
@total = 100
|
8
|
+
@progress = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def total=(num)
|
12
|
+
@total = num
|
13
|
+
update
|
14
|
+
end
|
15
|
+
|
16
|
+
def progress=(num)
|
17
|
+
update { num }
|
18
|
+
end
|
19
|
+
|
20
|
+
def increment(num=1)
|
21
|
+
update { @progress + num }
|
22
|
+
end
|
23
|
+
|
24
|
+
def decrement(num=1)
|
25
|
+
update { @progress - num }
|
26
|
+
end
|
27
|
+
|
28
|
+
def finish
|
29
|
+
update { @total }
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def update
|
35
|
+
@progress = yield if block_given?
|
36
|
+
@job.status.update(hash)
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def hash
|
41
|
+
{ progress: @progress, total: @total }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ActiveJob::Status
|
2
|
+
class Status
|
3
|
+
delegate :[], :to_s, :inspect, to: :read
|
4
|
+
delegate :queued?, :working?, :completed?, to: :status_inquiry
|
5
|
+
|
6
|
+
def initialize(job)
|
7
|
+
@job = job
|
8
|
+
end
|
9
|
+
|
10
|
+
def []= key, value
|
11
|
+
update(key => value)
|
12
|
+
end
|
13
|
+
|
14
|
+
def read
|
15
|
+
Storage.read(@job)
|
16
|
+
end
|
17
|
+
|
18
|
+
def update(message)
|
19
|
+
Storage.update(@job, message)
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete
|
23
|
+
Storage.delete(@job)
|
24
|
+
end
|
25
|
+
|
26
|
+
def job_id
|
27
|
+
Storage.job_id(@job)
|
28
|
+
end
|
29
|
+
|
30
|
+
def status
|
31
|
+
read[:status]
|
32
|
+
end
|
33
|
+
|
34
|
+
def progress
|
35
|
+
read[:progress].to_f / read[:total].to_f
|
36
|
+
end
|
37
|
+
|
38
|
+
def present?
|
39
|
+
read.present?
|
40
|
+
end
|
41
|
+
|
42
|
+
def status_inquiry
|
43
|
+
status.to_s.inquiry
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ActiveJob::Status
|
2
|
+
module Storage
|
3
|
+
class << self
|
4
|
+
def store
|
5
|
+
ActiveJob::Status.store
|
6
|
+
end
|
7
|
+
|
8
|
+
def job_id(job)
|
9
|
+
job.is_a?(String) ? job : job.job_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def key(job)
|
13
|
+
"activejob:status:#{job_id(job)}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def read(job)
|
17
|
+
store.read(key(job)) || {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def write(job, message)
|
21
|
+
store.write(key(job), message, expires_in: DEFAULT_EXPIRY)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update(job, message)
|
25
|
+
write(job, read(job).merge(message))
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete(job)
|
29
|
+
store.delete(key(job))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activejob-status
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Savater Sebastien
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activejob
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.2'
|
41
|
+
description: Monitor jobs created by ActiveJob, check their status and progress
|
42
|
+
email:
|
43
|
+
- savater.sebastien@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/activejob-status.rb
|
49
|
+
- lib/activejob-status/progress.rb
|
50
|
+
- lib/activejob-status/status.rb
|
51
|
+
- lib/activejob-status/storage.rb
|
52
|
+
- lib/activejob-status/version.rb
|
53
|
+
homepage: http://github.com/inkstak/activejob-status
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.4.6
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Monitor your jobs
|
77
|
+
test_files: []
|