jobba 1.6.0 → 1.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d8bc9c17314ba74b80cf4c79c5d638f9d35b83b
4
- data.tar.gz: e5f612733209502da66c0200cc924fb941d8f773
3
+ metadata.gz: 8b6fbe4f79c7707c269facfeb60eddd1af3f6983
4
+ data.tar.gz: 0d2910f8859ea8d05a1745a3cc58bbaf0ff34a2b
5
5
  SHA512:
6
- metadata.gz: e185dfac6ec0e3d5d1daad73b62abc307dd8098251c1889f8427dbf1137970a9bb6e24ccdfda10eeacbd7ddd29648ee28cc7a7a8b1e4ced5b1c664208a307527
7
- data.tar.gz: 259cd22746fb655039ca5e4b11c7095567c725ba03bb238445ef702ad24e07aa540eddab71613e21990508006050ddde68ec0173b6afc4cd32ecfdd3491ba541
6
+ metadata.gz: 6091608aa497bc8027fa30c23dbecf31c6d9d2e987177da8fed93cda20629ca35a26b3b806664a5e7983a45d4612ff5020857ab5752de11d66f059be81eadbb5
7
+ data.tar.gz: c81bb3aebf41dab11f2c94b37f6915d2ad4ead35586e78df8bea825427406ac128d531ea8c15a863258c2fefd70f24dbd5d00ae0d546a5e92b55a4f85ba34f6d
data/lib/jobba.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'delegate'
1
2
  require 'forwardable'
2
3
  require 'securerandom'
3
4
 
@@ -10,6 +11,7 @@ require "jobba/time"
10
11
  require "jobba/utils"
11
12
  require "jobba/configuration"
12
13
  require "jobba/common"
14
+ require "jobba/redis_with_expiration"
13
15
  require "jobba/state"
14
16
  require "jobba/status"
15
17
  require "jobba/statuses"
@@ -32,20 +34,14 @@ module Jobba
32
34
  end
33
35
 
34
36
  def self.redis
35
- @redis ||= Redis::Namespace.new(
36
- configuration.namespace,
37
- redis: Redis.new(configuration.redis_options || {})
37
+ @redis ||= Jobba::RedisWithExpiration.new(
38
+ Redis::Namespace.new(
39
+ configuration.namespace,
40
+ redis: Redis.new(configuration.redis_options || {})
41
+ )
38
42
  )
39
43
  end
40
44
 
41
- # Clears the whole shebang! USE WITH CARE!
42
- def self.clear_all_jobba_data!
43
- keys = Jobba.redis.keys("*")
44
- keys.each_slice(1000) do |some_keys|
45
- Jobba.redis.del(*some_keys)
46
- end
47
- end
48
-
49
45
  def self.cleanup(seconds_ago: 60*60*24*30*12, batch_size: 1000)
50
46
  start_time = Jobba::Time.now
51
47
  delete_before = start_time - seconds_ago
@@ -59,6 +55,12 @@ module Jobba
59
55
  jobs_count += num_jobs
60
56
  break if jobs.size < batch_size
61
57
  end
58
+ jobs_count
59
+ end
60
+
61
+ # Clears the whole shebang! USE WITH CARE!
62
+ def self.clear_all_jobba_data!
63
+ cleanup(seconds_ago: 0)
62
64
  end
63
65
 
64
66
  end
@@ -0,0 +1,68 @@
1
+ # This class provides Redis commands that automatically set key expiration.
2
+ # The only commands modified are commands that:
3
+ # 1. Take their (only) key as the first argument
4
+ # AND
5
+ # 2. Modify said key
6
+ # AND
7
+ # 3. Don't already set the key expiration by themselves
8
+ class Jobba::RedisWithExpiration < SimpleDelegator
9
+ # 68.years in seconds
10
+ EXPIRES_IN = 2145916800
11
+
12
+ EXPIRE_METHODS = [
13
+ :append,
14
+ :decr,
15
+ :decrby,
16
+ :hdel,
17
+ :hincrby,
18
+ :hincrbyfloat,
19
+ :hmset,
20
+ :hset,
21
+ :hsetnx,
22
+ :incr,
23
+ :incrby,
24
+ :incrbyfloat,
25
+ :linsert,
26
+ :lpop,
27
+ :lpush,
28
+ :lpushx,
29
+ :lrem,
30
+ :lset,
31
+ :ltrim,
32
+ :mapped_hmset,
33
+ :migrate,
34
+ :move,
35
+ :pfadd,
36
+ :pfmerge,
37
+ :restore,
38
+ :rpop,
39
+ :rpush,
40
+ :rpushx,
41
+ :sadd,
42
+ :set,
43
+ :setbit,
44
+ :setnx,
45
+ :setrange,
46
+ :sinterstore,
47
+ :smove,
48
+ :spop,
49
+ :srem,
50
+ :sunionstore,
51
+ :zadd,
52
+ :zincrby,
53
+ :zinterstore,
54
+ :zrem,
55
+ :zremrangebyrank,
56
+ :zremrangebyscore,
57
+ :zunionstore
58
+ ]
59
+
60
+ EXPIRE_METHODS.each do |method|
61
+ define_method method do |key, *args|
62
+ result = super key, *args
63
+ # Only set expiration if the command (seems to have) succeeded
64
+ expire key, EXPIRES_IN if result
65
+ result
66
+ end
67
+ end
68
+ end
data/lib/jobba/status.rb CHANGED
@@ -246,12 +246,12 @@ module Jobba
246
246
 
247
247
  if attrs[:persist]
248
248
  redis.multi do
249
- set({
249
+ set(
250
250
  id: id,
251
251
  progress: progress,
252
252
  errors: errors,
253
253
  attempt: attempt
254
- })
254
+ )
255
255
  move_to_state!(state)
256
256
  end
257
257
  end
data/lib/jobba/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jobba
2
- VERSION = "1.6.0"
2
+ VERSION = "1.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jobba
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-22 00:00:00.000000000 Z
11
+ date: 2018-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -135,6 +135,7 @@ files:
135
135
  - lib/jobba/exceptions.rb
136
136
  - lib/jobba/id_clause.rb
137
137
  - lib/jobba/query.rb
138
+ - lib/jobba/redis_with_expiration.rb
138
139
  - lib/jobba/state.rb
139
140
  - lib/jobba/status.rb
140
141
  - lib/jobba/statuses.rb