allq 0.1.3 → 0.1.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: 5cf263ffd2e2299767088b6584856c8c0a13057c
4
- data.tar.gz: df094c015698eb092e289558278dcaaae7533685
3
+ metadata.gz: 6b8559866f94f306c73d4c86db9df0cbed2f9d62
4
+ data.tar.gz: 83172c958ee6ebc754c633e70dab3cf38541b028
5
5
  SHA512:
6
- metadata.gz: ffd44c9714deffc0396f697b352718c60f0edad110006bb4c04bf7df83cd320e98a39aca6aecd8bc710e98c9780dc59ea7698e7051c906365cc04966d0f6625d
7
- data.tar.gz: c41e7d911f9dd4c0383c6d52f6a0be851ea9d3b4851ba34cd93447479c6fe2362004d0173d245e85110c39b07c4396b5ea08a3d775750f0522fdfcf0d516bd62
6
+ metadata.gz: 301c75daf192b1ea190f3ef063a33b1fb8968c8172166f729b2032c17cafd70b00aa41459696ecaea968c1a74ff2e667fcd353a680b43dfb884b2720c94e8322
7
+ data.tar.gz: 8f05b5205316930d0e89b01c6336039e530bdb20d54eb33894e0a239ed79910add9473872fb71303692321ceb87e72c020fa40f01020a91afa070610292c0cf9
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
- # source "https://rubygems.org"
1
+ source 'https://rubygems.org/'
2
2
 
3
- # git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # # Specify your gem's dependencies in allq.gemspec
6
- # gemspec
3
+ gem 'rspec'
data/lib/allq.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require_relative "allq/#{f}"
4
4
  end
5
5
 
6
- %w(base get delete done put release stats touch).each do |f|
6
+ %w(base get delete done put release stats touch kick peek clear bury parent_job).each do |f|
7
7
  require_relative "allq/actions/#{f}"
8
8
  end
9
9
 
@@ -0,0 +1,28 @@
1
+ class AllQ
2
+ class Bury < AllQ::Base
3
+
4
+ def snd(data)
5
+ job_id = data[:job_id]
6
+
7
+ send_data = base_send(job_id)
8
+ response = send_hash_as_json(send_data)
9
+ result = rcv(response)
10
+ return result
11
+ end
12
+
13
+ def rcv(data)
14
+ return nil if data.to_s == '' || data.to_s.strip == '{}'
15
+ JSON.parse(data)
16
+ end
17
+
18
+ def base_send(job_id)
19
+ {
20
+ 'action' => 'bury',
21
+ 'params' => {
22
+ 'job_id' => job_id
23
+ }
24
+ }
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ class AllQ
2
+ class Clear < AllQ::Base
3
+
4
+ def snd(data)
5
+ cache_type = data[:cache_type] || "all"
6
+
7
+ send_data = base_send(cache_type)
8
+ response = send_hash_as_json(send_data)
9
+ result = rcv(response)
10
+ rcv(response)
11
+ end
12
+
13
+ def rcv(data)
14
+ return nil if data.to_s == '' || data.to_s.strip == '{}'
15
+ JSON.parse(data)
16
+ end
17
+
18
+ def base_send(cache_type)
19
+ {
20
+ 'action' => 'clear',
21
+ 'params' => {
22
+ 'cache_type' => cache_type
23
+ }
24
+ }
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ class AllQ
2
+ class Kick < AllQ::Base
3
+
4
+ def snd(data)
5
+ result = nil
6
+ tube = data[:tube]
7
+
8
+ send_data = base_send(tube)
9
+ response = send_hash_as_json(send_data)
10
+ rcv(response)
11
+ end
12
+
13
+ def base_send(tube)
14
+ {
15
+ 'action' => 'kick',
16
+ 'params' => {
17
+ 'tube' => tube
18
+ }
19
+ }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ class AllQ
2
+ class ParentJob < AllQ::Base
3
+
4
+ def snd(data)
5
+ result = nil
6
+ tube = data.delete('tube')
7
+ body = data.delete('body')
8
+
9
+ send_data = base_send(tube, body, data)
10
+ response = send_hash_as_json(send_data)
11
+ result = rcv(response)
12
+ build_job(result)
13
+ end
14
+
15
+ def base_send(tube, body, options = {})
16
+ raise 'Must have tube name and body' unless tube && body
17
+ base = {
18
+ 'action' => 'set_parent_job',
19
+ 'params' => {
20
+ 'tube' => tube,
21
+ 'body' => body
22
+ }
23
+ }
24
+ base['params']['limit'] = options['limit'] if options['limit']
25
+ base['params']['noop'] = options['noop'] if options['noop']
26
+ base['params']['ttl'] = options['ttl'] if options['ttl']
27
+ base['params']['delay'] = options['delay'] if options['delay']
28
+ base['params']['parent_id'] = options['parent_id'] if options['parent_id']
29
+ return base
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,39 @@
1
+ class AllQ
2
+ class Peek < AllQ::Base
3
+
4
+ def snd(data)
5
+ result = nil
6
+ tube = data.delete(:tube)
7
+ buried = data.delete(:buried)
8
+
9
+ send_data = base_send(tube, buried)
10
+ response = send_hash_as_json(send_data)
11
+ rcv(response)
12
+ end
13
+
14
+ def rcv(data)
15
+ return nil if data.to_s == '' || data.to_s.strip == '{}'
16
+
17
+ result = JSON.parse(data)
18
+ puts "PEEK result #{result}"
19
+ if result['job']
20
+ return nil if result['job'].empty?
21
+ job = Job.new_from_hash(result['job'])
22
+ return job
23
+ end
24
+ nil
25
+ end
26
+
27
+ def base_send(tube, buried)
28
+ out = {
29
+ 'action' => 'peek',
30
+ 'params' => {
31
+ 'tube' => tube
32
+ }
33
+ }
34
+
35
+ out['params']['buried'] = 'true' if buried
36
+ out
37
+ end
38
+ end
39
+ end
data/lib/allq/client.rb CHANGED
@@ -14,19 +14,61 @@ class AllQ
14
14
  @stats_action = AllQ::Stats.new(@connection)
15
15
  @release_action = AllQ::Release.new(@connection)
16
16
  @touch_action = AllQ::Touch.new(@connection)
17
+ @kick_action = AllQ::Kick.new(@connection)
18
+ @bury_action = AllQ::Bury.new(@connection)
19
+ @clear_action = AllQ::Clear.new(@connection)
20
+ @peek_action = AllQ::Peek.new(@connection)
21
+ @delete_action = AllQ::Delete.new(@connection)
22
+ @parent_job_action = AllQ::ParentJob.new(@connection)
23
+ end
24
+
25
+ def parent_job(body, tube, ttl: 3600, delay: 0, parent_id: nil, priority: 5, limit: nil, noop: false)
26
+ data = {
27
+ 'body' => body,
28
+ 'tube' => tube,
29
+ 'delay' => delay,
30
+ 'ttl' => ttl,
31
+ 'priority' => priority,
32
+ 'parent_id' => parent_id,
33
+ 'limit' => limit,
34
+ 'noop' => noop
35
+ }
36
+ @parent_job_action.snd(data)
37
+ end
38
+
39
+ def kick(tube_name)
40
+ @kick_action.snd(tube: tube_name)
41
+ end
42
+
43
+ def clear(cache_type = "cache_type", value = "all")
44
+ @clear_action.snd(cache_type: :all)
45
+ end
46
+
47
+ def peek(tube_name)
48
+ @peek_action.snd(tube: tube_name, buried: false)
49
+ end
50
+
51
+ def peek_buried(tube_name)
52
+ @peek_action.snd(tube: tube_name, buried: true)
53
+ end
54
+
55
+ def bury(job)
56
+ raise "Can't 'bury' a Job that is nil. Please check for Nil job before burying." unless job
57
+ @bury_action.snd(job_id: job.id)
17
58
  end
18
59
 
19
60
  def get(tube_name)
20
61
  @get_action.snd(tube_name)
21
62
  end
22
63
 
23
- def put(body, tube, delay = 0, ttl = 3600, priority = 5)
64
+ def put(body, tube, ttl: 3600, delay: 0, parent_id: nil, priority: 5)
24
65
  data = {
25
66
  'body' => body,
26
67
  'tube' => tube,
27
68
  'delay' => delay,
28
69
  'ttl' => ttl,
29
- 'priority' => priority
70
+ 'priority' => priority,
71
+ 'parent_id' => parent_id
30
72
  }
31
73
  @put_action.snd(data)
32
74
  end
@@ -37,6 +79,7 @@ class AllQ
37
79
  end
38
80
 
39
81
  def touch(job)
82
+ raise "Can't 'touch' a Job that is nil. Please check for Nil job before 'touch'." unless job
40
83
  @touch_action.snd(job_id: job.id)
41
84
  end
42
85
 
@@ -45,14 +88,10 @@ class AllQ
45
88
  end
46
89
 
47
90
  def release(job)
91
+ raise "Can't 'release' a Job that is nil." unless job
48
92
  @release_action.snd(job_id: job.id)
49
93
  end
50
94
 
51
- def delete(job)
52
- end
53
-
54
- def kick(job)
55
- end
56
95
 
57
96
  end
58
97
  end
data/lib/allq/job.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class AllQ
2
2
 
3
3
  class Job
4
- attr_accessor :id, :q_server, :body, :expired_count
4
+ attr_accessor :id, :body, :expired_count
5
5
  def initialize(id, tube = nil, body = nil, expired_count = nil)
6
6
  @body = body
7
7
  @id = id
data/lib/allq/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Allq
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-15 00:00:00.000000000 Z
11
+ date: 2018-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,9 +72,14 @@ files:
72
72
  - bin/setup
73
73
  - lib/allq.rb
74
74
  - lib/allq/actions/base.rb
75
+ - lib/allq/actions/bury.rb
76
+ - lib/allq/actions/clear.rb
75
77
  - lib/allq/actions/delete.rb
76
78
  - lib/allq/actions/done.rb
77
79
  - lib/allq/actions/get.rb
80
+ - lib/allq/actions/kick.rb
81
+ - lib/allq/actions/parent_job.rb
82
+ - lib/allq/actions/peek.rb
78
83
  - lib/allq/actions/put.rb
79
84
  - lib/allq/actions/release.rb
80
85
  - lib/allq/actions/stats.rb