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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ea8bac2bfeb93d6844f4771f4bf9706735831ce
4
- data.tar.gz: 176590db71f11445b8fc2a82b9b2ff53af8fc65e
3
+ metadata.gz: 0b846ef69f7e610e0606b9bce25fb64edc49f1aa
4
+ data.tar.gz: bd3674f5d7c02c2d7ff7b2a935c3dc2920333bdc
5
5
  SHA512:
6
- metadata.gz: 8baecc6e6ab0a989125c51c35aa1c17fd0a4de621b1263e7b2bf8f5f8e03b5717732e3745878c72c8b1380990ab1f29e8fb0197d40e75cb5f9861c08fba2b952
7
- data.tar.gz: e3a0a23cc6dd05e7c2be3175f521c4d71abe39e3f182577e55089d0801c5c61e11c9574c882e54d65f0aa8ec4727b979517a1bac5e2698ce5df7437174516273
6
+ metadata.gz: de63ad633ce940138e4255fd0484c7025d5e14034df2398f81f0202429a38e8a9fb1f2b4a432a4251a49aa6dfa772a06e696df5100bb47116bb370a805781be4
7
+ data.tar.gz: 385e25254035bfd3f95d7652ac730df93427655b1d8a27dc896646121b7c835e6eed520bcee180619d9147a1642cd3663522375d62c6639be2a105214a4a164f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # ActiveJobStatus
2
2
 
3
+ ## 0.0.5
4
+ - Use ActiveSupport::Cache instead of Redis, reducing dependencies. Changes
5
+ from Gabe Kopley.
6
+
3
7
  ## 0.0.4
4
8
  - Change name of JobStatus::get_status argument batch_key to be batch_id
5
9
  - Add changelog
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 Redis values to track job status
12
- and batches of jobs. To prevent it from taking over all of your Redis, both jobs
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
@@ -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 "redis", "~> 3.2"
27
+ spec.add_runtime_dependency "activesupport", "~>4.2"
29
28
  end
@@ -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
- @@redis = Redis.new
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.redis.del(@batch_id) # delete any old batches
13
- ActiveJobStatus.redis.sadd(@batch_id, @job_ids)
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
- ActiveJobStatus.redis.sadd(@batch_id, job_ids)
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.redis.smembers(batch_id)
32
+ ActiveJobStatus.store.fetch(batch_id).to_a
32
33
  end
33
34
  end
34
35
  end
@@ -3,7 +3,7 @@ module ActiveJobStatus
3
3
  # Provides a way to check on the status of a given job
4
4
 
5
5
  def self.get_status(job_id:)
6
- status = ActiveJobStatus.redis.get(job_id)
6
+ status = ActiveJobStatus.store.fetch(job_id)
7
7
  status ? status.to_sym : nil
8
8
  end
9
9
  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.redis.set(job_id, "queued")
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.redis.set(job_id, status.to_s)
10
+ ActiveJobStatus.store.write(job_id, status.to_s)
13
11
  end
14
12
 
15
13
  def self.remove(job_id:)
16
- ActiveJobStatus.redis.del(job_id)
14
+ ActiveJobStatus.store.delete(job_id)
17
15
  end
18
16
  end
19
17
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveJobStatus
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -4,7 +4,9 @@ describe ActiveJobStatus::JobBatch do
4
4
 
5
5
  let!(:batch_id) { Time.now }
6
6
 
7
- let!(:redis) { ActiveJobStatus.redis }
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 create a redis set" do
27
+ it "should write to the cache store" do
26
28
  first_jobs.each do |job_id|
27
- expect(redis.smembers(batch_id)).to include job_id
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
- update_redis(id_array: total_jobs, job_status: :queued)
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
- update_redis(id_array: total_jobs, job_status: :working)
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
- clear_redis(id_array: total_jobs)
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 2
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 update_redis(id_array: [], job_status: :queued)
92
+ def update_store(id_array: [], job_status: :queued)
91
93
  id_array.each do |id|
92
- redis.set(id, job_status.to_s)
94
+ store.write(id, job_status.to_s)
93
95
  end
94
96
  end
95
97
 
96
- def clear_redis(id_array: [])
98
+ def clear_store(id_array: [])
97
99
  id_array.each do |id|
98
- redis.del(id)
100
+ store.delete(id)
99
101
  end
100
102
  end
101
103
  end
@@ -2,27 +2,29 @@ require "spec_helper"
2
2
 
3
3
  describe ActiveJobStatus::JobTracker do
4
4
 
5
- let!(:redis) { ActiveJobStatus.redis }
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(redis.get(job.job_id)).to eq "queued"
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(redis.get(job.job_id)).to eq "working"
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 redis key" do
25
+ it "should remove the job from the cache store" do
24
26
  ActiveJobStatus::JobTracker.remove(job_id: job.job_id)
25
- expect(redis.get(job.job_id)).to eq nil
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
@@ -3,6 +3,3 @@ CodeClimate::TestReporter.start
3
3
  require "active_job_status"
4
4
  include ActiveJob::TestHelper
5
5
  ActiveJob::Base.queue_adapter = :test
6
- require "mock_redis"
7
- ActiveJobStatus.redis = MockRedis.new
8
-
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
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-02-10 00:00:00.000000000 Z
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: redis
84
+ name: activesupport
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - "~>"
102
88
  - !ruby/object:Gem::Version
103
- version: '3.2'
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: '3.2'
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: