job_status 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +80 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/circle.yml +9 -0
- data/job_status.gemspec +28 -0
- data/lib/job_status/status.rb +62 -0
- data/lib/job_status/tracked_job.rb +67 -0
- data/lib/job_status/tracker.rb +35 -0
- data/lib/job_status/version.rb +7 -0
- data/lib/job_status.rb +22 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 37af72829cb512c9afb5f3219acdbca2bfb0de16
|
4
|
+
data.tar.gz: 23e586a7d4077ff2f080578db7e18fd4ab3b6322
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a9b0936d76c9829b6632edccc3344a73bffbd512b70ba016c491cc46d7da6853ef43d1479f3948d0cecc0fe92339dddfa1520ecd5643c94e4d7fc488cc13be9
|
7
|
+
data.tar.gz: 71b93c5aa0130bfd66a9ee847605658854e7ee01a4f0ef9df6687e8a826790eaa9b687fc663f48954e2a360f252f04e7c5889f1299d50bf70eabfac471fa87b9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# ActiveJob Status
|
2
|
+
|
3
|
+
Provides interface for ActiveJob to allow the passing of status information for running jobs.
|
4
|
+
|
5
|
+
This gem uses callbacks implemented within ActiveJob and ActiveSupport::Cache to values to track job status and allow the passing of job completion information.
|
6
|
+
|
7
|
+
Cached information is set to expire after 72 hours to prevent memory exhaustion issues.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'job_status'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install job_status
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
JobStatus needs to have a store configured to be used for the cache. Any ActiveSupport::Cache store is acceptable. The simplest to use is `ActiveSupport::Cache::MemoryStore`, to use the store configure an initializer within you application to set the store.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# config/initializers/active_job_status.rb
|
31
|
+
JobStatus.store = ActiveSupport::Cache::MemoryStore.new
|
32
|
+
```
|
33
|
+
|
34
|
+
Other memory stores are available, for example it is possible to use the Redis based store or MemCache based store.
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
Create ActiveJob worker as normal and add the callback handlers and class methods for reporting status.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
class MyJob < ActiveJob::Base
|
42
|
+
include JobStatus::TrackedJob
|
43
|
+
|
44
|
+
queue_as :urgent
|
45
|
+
|
46
|
+
def perform(*args)
|
47
|
+
# Set the total for a percentage
|
48
|
+
total(job_id: @job_id, total: 100)
|
49
|
+
|
50
|
+
# Do Stuff...
|
51
|
+
# Set current status through
|
52
|
+
at(job_id: @job_id, at: 95)
|
53
|
+
|
54
|
+
# Store data to be retrieved
|
55
|
+
store(job_id: @job_id, store: [{test: 1, name: "test"},{test: 2, name: "test 2"}])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
### Job Status
|
61
|
+
|
62
|
+
You can check the status of the job using the ActiveJob job_id.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
my_job = MyJob.perform_later
|
66
|
+
JobStatus::Status.get_status(job_id: my_job.job_id)
|
67
|
+
# => :queued, :working, :completed
|
68
|
+
```
|
69
|
+
|
70
|
+
More information can be found in the docs.
|
71
|
+
|
72
|
+
## Development
|
73
|
+
|
74
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
75
|
+
|
76
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/job_status.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "job_status"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/circle.yml
ADDED
data/job_status.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'job_status/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "job_status"
|
8
|
+
spec.version = JobStatus::VERSION
|
9
|
+
spec.authors = ["Stephen Kapp"]
|
10
|
+
spec.email = ["mort666@virus.org"]
|
11
|
+
|
12
|
+
spec.summary = %q{ActiveJob Status Extension}
|
13
|
+
spec.description = %q{Provide an interactive status interface for ActiveJob, uses ActiveSupport::Cache to provide store for status information}
|
14
|
+
spec.homepage = "http://github.com/mort666/job_status"
|
15
|
+
spec.license = "Apache-2.0"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'activejob'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
28
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module JobStatus
|
2
|
+
#
|
3
|
+
# Status Module, retrieve the status information from the store
|
4
|
+
#
|
5
|
+
module Status
|
6
|
+
#
|
7
|
+
# Get the Status from the store
|
8
|
+
#
|
9
|
+
# @param job_id [String] ActiveJob ID to query the store for
|
10
|
+
# @return [Symbol] status Returns status possible valuds
|
11
|
+
# :queued, :working, :completed
|
12
|
+
#
|
13
|
+
def self.get_status(job_id:)
|
14
|
+
status = JobStatus.store.fetch(job_id)
|
15
|
+
status ? status[:status] : nil
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Get the current progress from the store
|
20
|
+
#
|
21
|
+
# @param job_id [String] ActiveJob ID to query the store for
|
22
|
+
# @return [Integer] at Value stored by the work for the progress
|
23
|
+
#
|
24
|
+
def self.at(job_id:)
|
25
|
+
status = JobStatus.store.fetch(job_id)
|
26
|
+
status ? status[:at] : nil
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Get the stored data from the store
|
31
|
+
#
|
32
|
+
# @param job_id [String] ActiveJob ID to query the store for
|
33
|
+
# @return returns the stored data, could be any serializable object
|
34
|
+
#
|
35
|
+
def self.store(job_id:)
|
36
|
+
status = JobStatus.store.fetch(job_id)
|
37
|
+
status ? status[:store] : nil
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Get the Total from the store
|
42
|
+
#
|
43
|
+
# @param job_id [String] ActiveJob ID to query the store for
|
44
|
+
# @return [Integer] total Returns total used for the percentage
|
45
|
+
#
|
46
|
+
def self.total(job_id:)
|
47
|
+
status = JobStatus.store.fetch(job_id)
|
48
|
+
status ? status[:total] : nil
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Get the All Data from the store
|
53
|
+
#
|
54
|
+
# @param job_id [String] ActiveJob ID to query the store for
|
55
|
+
# @return returns all information held in the store for the job_id
|
56
|
+
#
|
57
|
+
def self.get_all(job_id:)
|
58
|
+
status = JobStatus.store.fetch(job_id)
|
59
|
+
status ? status : nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module JobStatus
|
2
|
+
#
|
3
|
+
# Methods to be included within a worker when this module is used with the
|
4
|
+
# include keyword
|
5
|
+
#
|
6
|
+
module TrackedJob
|
7
|
+
#
|
8
|
+
# Setup the callbacks within the worker class
|
9
|
+
#
|
10
|
+
# @param base base class which will be extended by this module
|
11
|
+
#
|
12
|
+
def self.included(base)
|
13
|
+
base.extend ClassMethods
|
14
|
+
base.class_eval do
|
15
|
+
before_enqueue { JobStatus::Tracker.enqueue(job_id: @job_id) }
|
16
|
+
|
17
|
+
before_perform { JobStatus::Tracker.update(job_id: @job_id, status: :working ) }
|
18
|
+
|
19
|
+
after_perform { JobStatus::Tracker.update(job_id: @job_id, status: :completed ) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Store the current position
|
25
|
+
#
|
26
|
+
# @param job_id [String] ActiveJob job_id to attach information to in storage
|
27
|
+
# @param at [Integer] Value to store for the current position
|
28
|
+
#
|
29
|
+
def at(job_id:, at:)
|
30
|
+
storage(job_id, :at, at)
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Store the the total for the job
|
35
|
+
#
|
36
|
+
# @param job_id [String] ActiveJob job_id to attach information to in storage
|
37
|
+
# @param total [Integer] Value to store for the total positions
|
38
|
+
#
|
39
|
+
def total(job_id:, total:)
|
40
|
+
storage(job_id, :total, total)
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Store data for the provided job_id
|
45
|
+
#
|
46
|
+
# @param job_id [String] ActiveJob job_id to attach information to in storage
|
47
|
+
# @param store [Object] Data to be save within the storage, can be any serializable object
|
48
|
+
#
|
49
|
+
def store(job_id:, store:)
|
50
|
+
storage(job_id, :store, store)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
#
|
55
|
+
# Interact with the storage to make the save while preserving previous contents
|
56
|
+
#
|
57
|
+
def storage(job_id, type, value)
|
58
|
+
cache = JobStatus.store.fetch(job_id)
|
59
|
+
cache[type] = value
|
60
|
+
JobStatus.store.write(job_id, cache)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Class Methods to be included
|
64
|
+
module ClassMethods
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module JobStatus
|
2
|
+
#
|
3
|
+
# Tracking routines used by the callbacks
|
4
|
+
#
|
5
|
+
module Tracker
|
6
|
+
#
|
7
|
+
# Sets the initial queued worker status and sets the expiry
|
8
|
+
#
|
9
|
+
# @param job_id [String] ActiveJob ID to use as the key in storage
|
10
|
+
#
|
11
|
+
def self.enqueue(job_id:)
|
12
|
+
JobStatus.store.write(job_id, {status: :queued, at: 0, total: 100}, expires_in: 259200)
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Stores the current status within the storage
|
17
|
+
#
|
18
|
+
# @param job_id [String] ActiveJob ID to use as the key in storage
|
19
|
+
#
|
20
|
+
def self.update(job_id:, status:)
|
21
|
+
cache = JobStatus.store.fetch(job_id)
|
22
|
+
cache[:status] = status
|
23
|
+
JobStatus.store.write(job_id, cache)
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Removes any information from the cache for the given job_id
|
28
|
+
#
|
29
|
+
# @param job_id [String] ActiveJob ID to use as the key in storage
|
30
|
+
#
|
31
|
+
def self.remove(job_id:)
|
32
|
+
JobStatus.store.delete(job_id)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/job_status.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'active_job'
|
2
|
+
|
3
|
+
require 'job_status/tracker'
|
4
|
+
require 'job_status/tracked_job'
|
5
|
+
require 'job_status/status'
|
6
|
+
|
7
|
+
require "job_status/version"
|
8
|
+
|
9
|
+
#
|
10
|
+
# ActiveJob Status Module Top Level Namespace
|
11
|
+
#
|
12
|
+
module JobStatus
|
13
|
+
#
|
14
|
+
# Adds the storage for the Cache
|
15
|
+
#
|
16
|
+
# @attr store storage for the ActiveSupport::Cache cache handler
|
17
|
+
# Options include ActiveSupport::Cache::MemoryStore
|
18
|
+
# ActiveSupport::Cache::RedisStore
|
19
|
+
class << self
|
20
|
+
attr_accessor :store
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: job_status
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephen Kapp
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-28 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: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: codeclimate-test-reporter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Provide an interactive status interface for ActiveJob, uses ActiveSupport::Cache
|
84
|
+
to provide store for status information
|
85
|
+
email:
|
86
|
+
- mort666@virus.org
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- circle.yml
|
98
|
+
- job_status.gemspec
|
99
|
+
- lib/job_status.rb
|
100
|
+
- lib/job_status/status.rb
|
101
|
+
- lib/job_status/tracked_job.rb
|
102
|
+
- lib/job_status/tracker.rb
|
103
|
+
- lib/job_status/version.rb
|
104
|
+
homepage: http://github.com/mort666/job_status
|
105
|
+
licenses:
|
106
|
+
- Apache-2.0
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.4.3
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: ActiveJob Status Extension
|
128
|
+
test_files: []
|
129
|
+
has_rdoc:
|