active_job_status 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +13 -3
- data/active_job_status.gemspec +1 -2
- data/lib/active_job_status.rb +2 -10
- data/lib/active_job_status/job_batch.rb +6 -5
- data/lib/active_job_status/job_status.rb +1 -1
- data/lib/active_job_status/job_tracker.rb +3 -5
- data/lib/active_job_status/version.rb +1 -1
- data/spec/job_batch_spec.rb +13 -11
- data/spec/job_tracker_spec.rb +7 -5
- data/spec/spec_helper.rb +0 -3
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b846ef69f7e610e0606b9bce25fb64edc49f1aa
|
4
|
+
data.tar.gz: bd3674f5d7c02c2d7ff7b2a935c3dc2920333bdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de63ad633ce940138e4255fd0484c7025d5e14034df2398f81f0202429a38e8a9fb1f2b4a432a4251a49aa6dfa772a06e696df5100bb47116bb370a805781be4
|
7
|
+
data.tar.gz: 385e25254035bfd3f95d7652ac730df93427655b1d8a27dc896646121b7c835e6eed520bcee180619d9147a1642cd3663522375d62c6639be2a105214a4a164f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -8,10 +8,11 @@ Uses Redis to provide simple job status information for ActiveJob. This is a
|
|
8
8
|
work in progress! Version 0.1.0 will probably be the first usable version. Until
|
9
9
|
then please expect frequent breaking changes, chaos, etc (Jan. 2015).
|
10
10
|
|
11
|
-
This gem uses ActiveJob callbacks to set simple
|
12
|
-
|
11
|
+
This gem uses ActiveJob callbacks to set simple ActiveSupport::Cache
|
12
|
+
values to track job status
|
13
|
+
and batches of jobs. To prevent it from taking over all of your memory, both jobs
|
13
14
|
and batch tracking information expires in 72 hours. Currently you can set
|
14
|
-
batches to expire at a different interval, but not jobs.
|
15
|
+
batches to expire at a different interval, but not jobs.
|
15
16
|
|
16
17
|
## Installation
|
17
18
|
|
@@ -29,6 +30,15 @@ Or install it yourself as:
|
|
29
30
|
|
30
31
|
$ gem install active_job_status
|
31
32
|
|
33
|
+
## Configuration
|
34
|
+
|
35
|
+
You need to tell ActiveJobStatus about your memory store. This is because
|
36
|
+
we anticipate including options to use different key value stores. For now
|
37
|
+
we only support ActiveSupport::Cache, so put this in an inializer. If you are
|
38
|
+
using Rails, you could put this in config/initializers/active_job_status.rb
|
39
|
+
|
40
|
+
ActiveJobStatus.store = ActiveSupport::Cache::MemoryStore.new
|
41
|
+
|
32
42
|
## Usage
|
33
43
|
|
34
44
|
Have your jobs descend from TrackableJob instead of ActiveJob::Base
|
data/active_job_status.gemspec
CHANGED
@@ -22,8 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
23
|
spec.add_development_dependency "rspec", "~> 3.0"
|
24
24
|
spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4"
|
25
|
-
spec.add_development_dependency "mock_redis", "~>0.14"
|
26
25
|
|
27
26
|
spec.add_runtime_dependency "activejob", "~>4.2"
|
28
|
-
spec.add_runtime_dependency "
|
27
|
+
spec.add_runtime_dependency "activesupport", "~>4.2"
|
29
28
|
end
|
data/lib/active_job_status.rb
CHANGED
@@ -3,18 +3,10 @@ require "active_job_status/job_tracker"
|
|
3
3
|
require "active_job_status/job_status"
|
4
4
|
require "active_job_status/job_batch"
|
5
5
|
require "active_job_status/version"
|
6
|
-
require "redis"
|
7
6
|
|
8
7
|
module ActiveJobStatus
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def self.redis= (redis)
|
13
|
-
@@redis = redis
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.redis
|
17
|
-
@@redis
|
8
|
+
class << self
|
9
|
+
attr_accessor :store
|
18
10
|
end
|
19
11
|
end
|
20
12
|
|
@@ -9,14 +9,15 @@ module ActiveJobStatus
|
|
9
9
|
@batch_id = batch_id
|
10
10
|
@job_ids = job_ids
|
11
11
|
@expire_in = expire_in
|
12
|
-
ActiveJobStatus.
|
13
|
-
ActiveJobStatus.
|
14
|
-
ActiveJobStatus.redis.expire(@batch_id, @expire_in)
|
12
|
+
ActiveJobStatus.store.delete(@batch_id) # delete any old batches
|
13
|
+
ActiveJobStatus.store.write(@batch_id, @job_ids, expires_in: @expire_in)
|
15
14
|
end
|
16
15
|
|
17
16
|
def add_jobs(job_ids:)
|
18
17
|
@job_ids = @job_ids + job_ids
|
19
|
-
|
18
|
+
# TODO re-optimize for redis store with sadd
|
19
|
+
existing_job_ids = ActiveJobStatus.store.fetch(@batch_id)
|
20
|
+
ActiveJobStatus.store.write(@batch_id, existing_job_ids.to_a | job_ids)
|
20
21
|
end
|
21
22
|
|
22
23
|
def completed?
|
@@ -28,7 +29,7 @@ module ActiveJobStatus
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def self.find(batch_id:)
|
31
|
-
ActiveJobStatus.
|
32
|
+
ActiveJobStatus.store.fetch(batch_id).to_a
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
@@ -1,19 +1,17 @@
|
|
1
1
|
module ActiveJobStatus
|
2
2
|
module JobTracker
|
3
3
|
# Provides methods to CRUD job status records in Redis
|
4
|
-
require "redis"
|
5
4
|
|
6
5
|
def self.enqueue(job_id:)
|
7
|
-
ActiveJobStatus.
|
8
|
-
ActiveJobStatus.redis.expire(job_id, 259200)
|
6
|
+
ActiveJobStatus.store.write(job_id, "queued", expires_in: 259200)
|
9
7
|
end
|
10
8
|
|
11
9
|
def self.update(job_id:, status:)
|
12
|
-
ActiveJobStatus.
|
10
|
+
ActiveJobStatus.store.write(job_id, status.to_s)
|
13
11
|
end
|
14
12
|
|
15
13
|
def self.remove(job_id:)
|
16
|
-
ActiveJobStatus.
|
14
|
+
ActiveJobStatus.store.delete(job_id)
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
data/spec/job_batch_spec.rb
CHANGED
@@ -4,7 +4,9 @@ describe ActiveJobStatus::JobBatch do
|
|
4
4
|
|
5
5
|
let!(:batch_id) { Time.now }
|
6
6
|
|
7
|
-
let!(:
|
7
|
+
let!(:store) {
|
8
|
+
ActiveJobStatus.store = ActiveSupport::Cache::MemoryStore.new
|
9
|
+
}
|
8
10
|
|
9
11
|
let!(:job1) { TrackableJob.perform_later }
|
10
12
|
let!(:job2) { TrackableJob.perform_later }
|
@@ -22,9 +24,9 @@ describe ActiveJobStatus::JobBatch do
|
|
22
24
|
it "should create an object" do
|
23
25
|
expect(batch).to be_an_instance_of ActiveJobStatus::JobBatch
|
24
26
|
end
|
25
|
-
it "should
|
27
|
+
it "should write to the cache store" do
|
26
28
|
first_jobs.each do |job_id|
|
27
|
-
expect(
|
29
|
+
expect(store.fetch(batch_id)).to include job_id
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
@@ -41,15 +43,15 @@ describe ActiveJobStatus::JobBatch do
|
|
41
43
|
|
42
44
|
describe "#completed?" do
|
43
45
|
it "should be false when jobs are queued" do
|
44
|
-
|
46
|
+
update_store(id_array: total_jobs, job_status: :queued)
|
45
47
|
expect(batch.completed?).to be_falsey
|
46
48
|
end
|
47
49
|
it "should be false when jobs are working" do
|
48
|
-
|
50
|
+
update_store(id_array: total_jobs, job_status: :working)
|
49
51
|
expect(batch.completed?).to be_falsey
|
50
52
|
end
|
51
53
|
it "should be true when jobs are completed" do
|
52
|
-
|
54
|
+
clear_store(id_array: total_jobs)
|
53
55
|
expect(batch.completed?).to be_truthy
|
54
56
|
end
|
55
57
|
end
|
@@ -79,7 +81,7 @@ describe ActiveJobStatus::JobBatch do
|
|
79
81
|
ActiveJobStatus::JobBatch.new(batch_id: "expiry",
|
80
82
|
job_ids: first_jobs,
|
81
83
|
expire_in: 1)
|
82
|
-
sleep
|
84
|
+
sleep 1 # TODO replace with timecop, if possible
|
83
85
|
expect(ActiveJobStatus::JobBatch.find(batch_id: "expiry")).to be_empty
|
84
86
|
|
85
87
|
end
|
@@ -87,15 +89,15 @@ describe ActiveJobStatus::JobBatch do
|
|
87
89
|
|
88
90
|
##### HELPERS
|
89
91
|
|
90
|
-
def
|
92
|
+
def update_store(id_array: [], job_status: :queued)
|
91
93
|
id_array.each do |id|
|
92
|
-
|
94
|
+
store.write(id, job_status.to_s)
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
96
|
-
def
|
98
|
+
def clear_store(id_array: [])
|
97
99
|
id_array.each do |id|
|
98
|
-
|
100
|
+
store.delete(id)
|
99
101
|
end
|
100
102
|
end
|
101
103
|
end
|
data/spec/job_tracker_spec.rb
CHANGED
@@ -2,27 +2,29 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe ActiveJobStatus::JobTracker do
|
4
4
|
|
5
|
-
let!(:
|
5
|
+
let!(:store) {
|
6
|
+
ActiveJobStatus.store = ActiveSupport::Cache::MemoryStore.new
|
7
|
+
}
|
6
8
|
let(:job) { TrackableJob.new.enqueue }
|
7
9
|
|
8
10
|
describe "::enqueue" do
|
9
11
|
it "should enqueue a job" do
|
10
12
|
ActiveJobStatus::JobTracker.enqueue(job_id: job.job_id)
|
11
|
-
expect(
|
13
|
+
expect(store.fetch(job.job_id)).to eq "queued"
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
17
|
describe "::update" do
|
16
18
|
it "should update a job status" do
|
17
19
|
ActiveJobStatus::JobTracker.update(job_id: job.job_id, status: :working)
|
18
|
-
expect(
|
20
|
+
expect(store.fetch(job.job_id)).to eq "working"
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
24
|
describe "::remove" do
|
23
|
-
it "should remove the
|
25
|
+
it "should remove the job from the cache store" do
|
24
26
|
ActiveJobStatus::JobTracker.remove(job_id: job.job_id)
|
25
|
-
expect(
|
27
|
+
expect(store.fetch(job.job_id)).to eq nil
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_job_status
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Johnson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.4'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: mock_redis
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0.14'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0.14'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: activejob
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,19 +81,19 @@ dependencies:
|
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '4.2'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
84
|
+
name: activesupport
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
89
|
+
version: '4.2'
|
104
90
|
type: :runtime
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
94
|
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
96
|
+
version: '4.2'
|
111
97
|
description: Job status and batches for ActiveJob. Create trackable jobs, check their
|
112
98
|
status, and batch them together.
|
113
99
|
email:
|