kue_ruby 0.1.0 → 0.2.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: 9cdf16b74aeb5f3824cf9b19e9b54694eaa97194
4
- data.tar.gz: ca8790a2122e3d2adb8294440abdca5e33b7e63d
3
+ metadata.gz: 9a7ef81e78f3103b8b2e89756641fe6b0ef8e194
4
+ data.tar.gz: 97cca0f205ab8efae8e1bb02df07db5846e09be5
5
5
  SHA512:
6
- metadata.gz: 9eabcc458897594fb456eda0986c13a37a5a9946e90bbf15544235258830cecca8329720ef30633e77961bccfbd49b6518c18ae281d3178632a9981a9a901b83
7
- data.tar.gz: d00523856d5a2dc10d498cf87c9bc7ff99940737562f5d3bf132bd6553838e0c44c1f63a12693993eb970eb82e286fb62ee6a23627b427a22de0d3de7f47e57e
6
+ metadata.gz: 3a153d3f1dbdadc972e2bdb93a42f3f2040eae9bc93a628abb9f7edcc1d0d5c8bfe4c5d660a8b032fff57ce227dfe173c5f8293747a462fdb153331c6009d720
7
+ data.tar.gz: 3f787785064b73b3c7294adbc4d36058b1af5e9967df40f96fac307ff3d9910d2f36874e69dd4d1a5d518a554cc7ce3aa8979bfee9897643a302e102727c1dec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kue_ruby (0.1.0)
4
+ kue_ruby (0.2.0)
5
5
  redis (~> 4.0.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -8,7 +8,7 @@ kue = KueRuby.new(redis: Redis.new)
8
8
  job = kue.create_job(type: 'foobar', data: { foo: 2 })
9
9
  jobp = kue.create_job(type: 'foobaz', data: { foo: 2 }, priority: -1, max_attempts: 3)
10
10
  job.max_attempts = 5
11
- job = job.save kue.redis
11
+ job = job.save kue
12
12
  ```
13
13
 
14
14
  Right now, this gem only supports creating jobs in Kue. Feel free to contribute with more!
@@ -4,16 +4,18 @@ require 'redis'
4
4
 
5
5
  # Interface with the Automattic Kue redis store
6
6
  class KueRuby
7
- attr_reader :redis
7
+ attr_reader :redis, :prefix
8
8
 
9
9
  # Create a new client instance
10
10
  #
11
11
  # @param Hash options
12
12
  # @option options Redis :redis an instance of `redis`
13
+ # @option options [String] :prefix namespace in redis (default is q)
13
14
  #
14
15
  # @return [KueRuby] a new kue client instance
15
16
  def initialize(options = {})
16
17
  @redis = options[:redis]
18
+ @prefix = options[:prefix] ? options[:prefix] : 'q'
17
19
  super()
18
20
  end
19
21
 
@@ -52,14 +54,14 @@ class KueRuby
52
54
  job.state = 'inactive'
53
55
  job.created_at = Time.now
54
56
  job.backoff = { delay: 60 * 1000, type: 'exponential' }
55
- job.id = @redis.incr 'q.ids'
57
+ job.id = @redis.incr "#{@prefix}.ids"
56
58
  job.zid = create_fifo job.id
57
- @redis.sadd 'q:job:types', job.type
58
- job.save @redis
59
- @redis.zadd('q:jobs', job.priority, job.zid)
60
- @redis.zadd('q:jobs:inactive', job.priority, job.zid)
61
- @redis.zadd("q:jobs:#{job.type}:inactive", job.priority, job.zid)
62
- @redis.lpush("q:#{job.type}:jobs", 1)
59
+ @redis.sadd "#{@prefix}:job:types", job.type
60
+ job.save self
61
+ @redis.zadd("#{@prefix}:jobs", job.priority, job.zid)
62
+ @redis.zadd("#{@prefix}:jobs:inactive", job.priority, job.zid)
63
+ @redis.zadd("#{@prefix}:jobs:#{job.type}:inactive", job.priority, job.zid)
64
+ @redis.lpush("#{@prefix}:#{job.type}:jobs", 1)
63
65
  job
64
66
  end
65
67
 
@@ -76,21 +78,21 @@ class KueRuby
76
78
 
77
79
  # Save job data to redis kue
78
80
  #
79
- # @param Redis redis instance
81
+ # @param KueRuby KueRuby instance with redis connection
80
82
  #
81
83
  # @return [KueJob]
82
- def save(redis)
83
- redis.hmset(
84
- "q:job:#{id}",
85
- 'max_attempts', max_attempts.to_i,
86
- 'backoff', backoff.to_json,
87
- 'type', type,
88
- 'created_at', (created_at.to_f * 1000).to_i,
89
- 'updated_at', (Time.now.to_f * 1000).to_i,
90
- 'promote_at', (Time.now.to_f * 1000).to_i + delay,
91
- 'priority', priority.to_i,
92
- 'data', data.to_json,
93
- 'state', state
84
+ def save(kue)
85
+ kue.redis.hmset(
86
+ "#{kue.prefix}:job:#{id}",
87
+ 'max_attempts', max_attempts.to_i,
88
+ 'backoff', backoff.to_json,
89
+ 'type', type,
90
+ 'created_at', (created_at.to_f * 1000).to_i,
91
+ 'updated_at', (Time.now.to_f * 1000).to_i,
92
+ 'promote_at', (Time.now.to_f * 1000).to_i + delay,
93
+ 'priority', priority.to_i,
94
+ 'data', data.to_json,
95
+ 'state', state
94
96
  )
95
97
  self
96
98
  end
@@ -1,3 +1,3 @@
1
1
  class KueRuby
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kue_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Beckman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-21 00:00:00.000000000 Z
11
+ date: 2017-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -99,7 +99,6 @@ files:
99
99
  - Rakefile
100
100
  - bin/console
101
101
  - bin/setup
102
- - dump.rdb
103
102
  - kue_ruby.gemspec
104
103
  - lib/kue_ruby.rb
105
104
  - lib/kue_ruby/version.rb
data/dump.rdb DELETED
Binary file