jobba 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jobba.rb +13 -11
- data/lib/jobba/redis_with_expiration.rb +68 -0
- data/lib/jobba/status.rb +2 -2
- data/lib/jobba/version.rb +1 -1
- 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: 8b6fbe4f79c7707c269facfeb60eddd1af3f6983
|
4
|
+
data.tar.gz: 0d2910f8859ea8d05a1745a3cc58bbaf0ff34a2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 ||=
|
36
|
-
|
37
|
-
|
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
data/lib/jobba/version.rb
CHANGED
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.
|
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:
|
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
|