active_job_status 0.0.3 → 0.0.4
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +3 -3
- data/lib/active_job_status/job_batch.rb +9 -9
- data/lib/active_job_status/version.rb +1 -1
- data/spec/job_batch_spec.rb +10 -10
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ea8bac2bfeb93d6844f4771f4bf9706735831ce
|
4
|
+
data.tar.gz: 176590db71f11445b8fc2a82b9b2ff53af8fc65e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8baecc6e6ab0a989125c51c35aa1c17fd0a4de621b1263e7b2bf8f5f8e03b5717732e3745878c72c8b1380990ab1f29e8fb0197d40e75cb5f9861c08fba2b952
|
7
|
+
data.tar.gz: e3a0a23cc6dd05e7c2be3175f521c4d71abe39e3f182577e55089d0801c5c61e11c9574c882e54d65f0aa8ec4727b979517a1bac5e2698ce5df7437174516273
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -50,14 +50,14 @@ exists, its jobs will be overwritten with the supplied list.
|
|
50
50
|
|
51
51
|
my_key = "230923asdlkj230923"
|
52
52
|
my_jobs = [my_first_job.job_id, my_second_job.job_id]
|
53
|
-
my_batch = ActiveJobStatus::JobBatch.new(
|
53
|
+
my_batch = ActiveJobStatus::JobBatch.new(batch_id: my_key, job_ids: my_jobs)
|
54
54
|
|
55
55
|
Batches expire after 72 hours (259200 seconds).
|
56
56
|
You can change that by passing the initalizer an integer value (in seconds).
|
57
57
|
|
58
58
|
my_key = "230923asdlkj230923"
|
59
59
|
my_jobs = [my_first_job.job_id, my_second_job.job_id]
|
60
|
-
my_batch = ActiveJobStatus::JobBatch.new(
|
60
|
+
my_batch = ActiveJobStatus::JobBatch.new(batch_id: my_key,
|
61
61
|
job_ids: my_jobs,
|
62
62
|
expire_in: 500000)
|
63
63
|
|
@@ -73,7 +73,7 @@ And you can ask the batch if all the jobs are completed or not.
|
|
73
73
|
|
74
74
|
You can ask the batch for other bits of information.
|
75
75
|
|
76
|
-
batch.
|
76
|
+
batch.batch_id
|
77
77
|
# => "230923asdlkj230923"
|
78
78
|
batch.job_ids
|
79
79
|
# => ["b67af7a0-3ed2-4661-a2d5-ff6b6a254886", "6c0216b9-ea0c-4ee9-a3b2-501faa919a66"]
|
@@ -1,22 +1,22 @@
|
|
1
1
|
module ActiveJobStatus
|
2
2
|
class JobBatch
|
3
3
|
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :batch_id
|
5
5
|
attr_reader :job_ids
|
6
6
|
attr_reader :expire_in
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
8
|
+
def initialize(batch_id:, job_ids:, expire_in: 259200)
|
9
|
+
@batch_id = batch_id
|
10
10
|
@job_ids = job_ids
|
11
11
|
@expire_in = expire_in
|
12
|
-
ActiveJobStatus.redis.del(@
|
13
|
-
ActiveJobStatus.redis.sadd(@
|
14
|
-
ActiveJobStatus.redis.expire(@
|
12
|
+
ActiveJobStatus.redis.del(@batch_id) # delete any old batches
|
13
|
+
ActiveJobStatus.redis.sadd(@batch_id, @job_ids)
|
14
|
+
ActiveJobStatus.redis.expire(@batch_id, @expire_in)
|
15
15
|
end
|
16
16
|
|
17
17
|
def add_jobs(job_ids:)
|
18
18
|
@job_ids = @job_ids + job_ids
|
19
|
-
ActiveJobStatus.redis.sadd(@
|
19
|
+
ActiveJobStatus.redis.sadd(@batch_id, job_ids)
|
20
20
|
end
|
21
21
|
|
22
22
|
def completed?
|
@@ -27,8 +27,8 @@ module ActiveJobStatus
|
|
27
27
|
!job_statuses.any?
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.find(
|
31
|
-
ActiveJobStatus.redis.smembers(
|
30
|
+
def self.find(batch_id:)
|
31
|
+
ActiveJobStatus.redis.smembers(batch_id)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/spec/job_batch_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe ActiveJobStatus::JobBatch do
|
4
4
|
|
5
|
-
let!(:
|
5
|
+
let!(:batch_id) { Time.now }
|
6
6
|
|
7
7
|
let!(:redis) { ActiveJobStatus.redis }
|
8
8
|
|
@@ -15,7 +15,7 @@ describe ActiveJobStatus::JobBatch do
|
|
15
15
|
let!(:addl_jobs) { [job3.job_id, job4.job_id] }
|
16
16
|
let!(:total_jobs) { first_jobs + addl_jobs }
|
17
17
|
|
18
|
-
let!(:batch) { ActiveJobStatus::JobBatch.new(
|
18
|
+
let!(:batch) { ActiveJobStatus::JobBatch.new(batch_id: batch_id,
|
19
19
|
job_ids: first_jobs) }
|
20
20
|
|
21
21
|
describe "#initialize" do
|
@@ -24,7 +24,7 @@ describe ActiveJobStatus::JobBatch do
|
|
24
24
|
end
|
25
25
|
it "should create a redis set" do
|
26
26
|
first_jobs.each do |job_id|
|
27
|
-
expect(redis.smembers(
|
27
|
+
expect(redis.smembers(batch_id)).to include job_id
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -33,7 +33,7 @@ describe ActiveJobStatus::JobBatch do
|
|
33
33
|
it "should add jobs to the set" do
|
34
34
|
batch.add_jobs(job_ids: addl_jobs)
|
35
35
|
total_jobs.each do |job_id|
|
36
|
-
expect(ActiveJobStatus::JobBatch.find(
|
36
|
+
expect(ActiveJobStatus::JobBatch.find(batch_id: batch_id)).to \
|
37
37
|
include job_id
|
38
38
|
end
|
39
39
|
end
|
@@ -56,31 +56,31 @@ describe ActiveJobStatus::JobBatch do
|
|
56
56
|
|
57
57
|
describe "::find" do
|
58
58
|
it "should return an array of jobs when a batch exists" do
|
59
|
-
expect(ActiveJobStatus::JobBatch.find(
|
59
|
+
expect(ActiveJobStatus::JobBatch.find(batch_id: batch_id)).to \
|
60
60
|
be_an_instance_of Array
|
61
61
|
end
|
62
62
|
it "should return the correct jobs" do
|
63
|
-
expect(ActiveJobStatus::JobBatch.find(
|
63
|
+
expect(ActiveJobStatus::JobBatch.find(batch_id: batch_id)).to \
|
64
64
|
eq first_jobs
|
65
65
|
end
|
66
66
|
it "should return nil when no batch exists" do
|
67
|
-
expect(ActiveJobStatus::JobBatch.find(
|
67
|
+
expect(ActiveJobStatus::JobBatch.find(batch_id: "45")).to eq []
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
describe "expiring job" do
|
72
72
|
it "should allow the expiration time to be set in seconds" do
|
73
|
-
expect(ActiveJobStatus::JobBatch.new(
|
73
|
+
expect(ActiveJobStatus::JobBatch.new(batch_id: "newkey",
|
74
74
|
job_ids: first_jobs,
|
75
75
|
expire_in: 200000)).to \
|
76
76
|
be_an_instance_of ActiveJobStatus::JobBatch
|
77
77
|
end
|
78
78
|
it "should expire" do
|
79
|
-
ActiveJobStatus::JobBatch.new(
|
79
|
+
ActiveJobStatus::JobBatch.new(batch_id: "expiry",
|
80
80
|
job_ids: first_jobs,
|
81
81
|
expire_in: 1)
|
82
82
|
sleep 2
|
83
|
-
expect(ActiveJobStatus::JobBatch.find(
|
83
|
+
expect(ActiveJobStatus::JobBatch.find(batch_id: "expiry")).to be_empty
|
84
84
|
|
85
85
|
end
|
86
86
|
end
|
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.4
|
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-02-
|
11
|
+
date: 2015-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -118,6 +118,7 @@ extra_rdoc_files: []
|
|
118
118
|
files:
|
119
119
|
- ".gitignore"
|
120
120
|
- ".travis.yml"
|
121
|
+
- CHANGELOG.md
|
121
122
|
- Gemfile
|
122
123
|
- LICENSE.txt
|
123
124
|
- README.md
|