allq 0.1.2 → 0.1.3

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: '089a863cd091965dc37950a0a320af94188e2c28'
4
- data.tar.gz: '038c6a4707a94fd07f2dabe30f302efbbe744281'
3
+ metadata.gz: 5cf263ffd2e2299767088b6584856c8c0a13057c
4
+ data.tar.gz: df094c015698eb092e289558278dcaaae7533685
5
5
  SHA512:
6
- metadata.gz: 836ede28d65728ab4b1aa3a3f2cac326ff3a245f7ec8a9897399a6bae0b4d5de2d262b6ca8e97d3321875ab6c83de5004b7d18ab72c7057eefab9745886b4b92
7
- data.tar.gz: ac2bac87b73031f2d75ed0e5655f18ade042198d52a52219177a906377d41363be6c354f2621bb145297ff14c05f0adf3e5ad6ff5fb9f8eed2abef83d7b9028d
6
+ metadata.gz: ffd44c9714deffc0396f697b352718c60f0edad110006bb4c04bf7df83cd320e98a39aca6aecd8bc710e98c9780dc59ea7698e7051c906365cc04966d0f6625d
7
+ data.tar.gz: c41e7d911f9dd4c0383c6d52f6a0be851ea9d3b4851ba34cd93447479c6fe2362004d0173d245e85110c39b07c4396b5ea08a3d775750f0522fdfcf0d516bd62
@@ -3,7 +3,6 @@ require 'json'
3
3
  class AllQ
4
4
  # Base class for handling allq actions
5
5
  class Base
6
- @requires_q_server = true
7
6
 
8
7
  def initialize(connection)
9
8
  @connection = connection
@@ -24,7 +23,6 @@ class AllQ
24
23
  def send_hash_as_json(data_hash)
25
24
  if @requires_q_server
26
25
  params = data_hash["params"]
27
- raise data_hash["action"] + " must have q_server set" unless data_hash["params"]["q_server"]
28
26
  end
29
27
  transmit_data = data_hash.to_json
30
28
  result = nil
@@ -38,9 +36,8 @@ class AllQ
38
36
  result_hash = JSON.parse(result)
39
37
  job_info = result_hash["job"]
40
38
  job_id = job_info["job_id"]
41
- q_server = job_info["q_server"]
42
39
 
43
- job = Job.new(job_id, q_server)
40
+ job = Job.new(job_id)
44
41
  # -- Optional fields
45
42
  job.body = job_info["body"] if job_info["body"]
46
43
  job.expired_count = job_info["expired_count"] if job_info["expired_count"]
@@ -3,9 +3,8 @@ class AllQ
3
3
 
4
4
  def snd(data)
5
5
  job_id = data[:job_id]
6
- q_server = data[:q_server]
7
6
 
8
- send_data = base_send(job_id, q_server)
7
+ send_data = base_send(job_id)
9
8
  response = send_hash_as_json(send_data)
10
9
  result = rcv(response)
11
10
  return JSON.parse(result)
@@ -15,8 +14,7 @@ class AllQ
15
14
  {
16
15
  'action' => 'delete',
17
16
  'params' => {
18
- 'job_id' => job_id,
19
- 'q_server' => q_server
17
+ 'job_id' => job_id
20
18
  }
21
19
  }
22
20
  end
@@ -3,19 +3,17 @@ class AllQ
3
3
 
4
4
  def snd(data)
5
5
  job_id = data[:job_id]
6
- q_server = data[:q_server]
7
6
 
8
- send_data = base_send(job_id, q_server)
7
+ send_data = base_send(job_id)
9
8
  response = send_hash_as_json(send_data)
10
9
  rcv(response)
11
10
  end
12
11
 
13
- def base_send(job_id, q_server)
12
+ def base_send(job_id)
14
13
  {
15
14
  'action' => 'done',
16
15
  'params' => {
17
- 'job_id' => job_id,
18
- 'q_server' => q_server
16
+ 'job_id' => job_id
19
17
  }
20
18
  }
21
19
  end
@@ -1,14 +1,11 @@
1
1
  class AllQ
2
2
  class Get < AllQ::Base
3
3
 
4
- def setup
5
- @requires_q_server = false
6
- end
7
-
8
4
  def rcv(data)
9
5
  return nil if data.to_s == '' || data.to_s.strip == '{}'
10
6
 
11
7
  result = JSON.parse(data)
8
+ puts "GET result #{result}"
12
9
  if result['job']
13
10
  return nil if result['job'].empty?
14
11
  job = Job.new_from_hash(result['job'])
@@ -1,10 +1,6 @@
1
1
  class AllQ
2
2
  class Put < AllQ::Base
3
3
 
4
- def setup
5
- @requires_q_server = false
6
- end
7
-
8
4
  def snd(data)
9
5
  result = nil
10
6
  tube = data.delete('tube')
@@ -3,9 +3,7 @@ class AllQ
3
3
 
4
4
  def snd(data)
5
5
  job_id = data[:job_id]
6
- q_server = data[:q_server]
7
-
8
- send_data = base_send(job_id, q_server)
6
+ send_data = base_send(job_id)
9
7
  response = send_hash_as_json(send_data)
10
8
  result = rcv(response)
11
9
  return result["release"] && result["release"]["job_id"]
@@ -16,12 +14,11 @@ class AllQ
16
14
  JSON.parse(data)
17
15
  end
18
16
 
19
- def base_send(job_id, q_server)
17
+ def base_send(job_id)
20
18
  {
21
19
  'action' => 'release',
22
20
  'params' => {
23
- 'job_id' => job_id,
24
- 'q_server' => q_server
21
+ 'job_id' => job_id
25
22
  }
26
23
  }
27
24
  end
@@ -3,9 +3,8 @@ class AllQ
3
3
 
4
4
  def snd(data)
5
5
  job_id = data[:job_id]
6
- q_server = data[:q_server]
7
6
 
8
- send_data = base_send(job_id, q_server)
7
+ send_data = base_send(job_id)
9
8
  response = send_hash_as_json(send_data)
10
9
  result = rcv(response)
11
10
  return result["touch"] && result["touch"]["job_id"]
@@ -16,11 +15,10 @@ class AllQ
16
15
  JSON.parse(data)
17
16
  end
18
17
 
19
- def base_send(job_id, q_server)
18
+ def base_send(job_id)
20
19
  {
21
20
  'action' => 'touch',
22
21
  'params' => {
23
- 'q_server' => q_server,
24
22
  'job_id' => job_id
25
23
  }
26
24
  }
@@ -33,11 +33,11 @@ class AllQ
33
33
 
34
34
  def done(job)
35
35
  raise "Can't set 'done' on a Job that is nil. Please check for Nil job before setting done." unless job
36
- @done_action.snd(job_id: job.id, q_server: job.q_server)
36
+ @done_action.snd(job_id: job.id)
37
37
  end
38
38
 
39
39
  def touch(job)
40
- @touch_action.snd(job_id: job.id, q_server: job.q_server)
40
+ @touch_action.snd(job_id: job.id)
41
41
  end
42
42
 
43
43
  def stats
@@ -45,7 +45,7 @@ class AllQ
45
45
  end
46
46
 
47
47
  def release(job)
48
- @release_action.snd(job_id: job.id, q_server: job.q_server)
48
+ @release_action.snd(job_id: job.id)
49
49
  end
50
50
 
51
51
  def delete(job)
@@ -2,9 +2,8 @@ class AllQ
2
2
 
3
3
  class Job
4
4
  attr_accessor :id, :q_server, :body, :expired_count
5
- def initialize(id, q_server, tube = nil, body = nil, expired_count = nil)
5
+ def initialize(id, tube = nil, body = nil, expired_count = nil)
6
6
  @body = body
7
- @q_server = q_server
8
7
  @id = id
9
8
  @tube = tube
10
9
  @expired_count = expired_count
@@ -12,8 +11,7 @@ class AllQ
12
11
 
13
12
  def to_hash
14
13
  {
15
- 'id' => @id,
16
- 'q_server' => @q_server,
14
+ 'job_id' => @id,
17
15
  'body' => @body,
18
16
  'tube' => @tube,
19
17
  'expired_count' => @expired_count
@@ -55,13 +53,11 @@ class AllQ
55
53
  def self.new_from_hash(hash)
56
54
  puts hash.inspect
57
55
  begin
58
- id = hash.fetch('id')
56
+ id = hash.fetch('job_id')
59
57
  body = hash.fetch('body')
60
58
  tube = hash.fetch('tube')
61
59
  expired_count = hash.fetch('expired_count')
62
- q_server = hash.fetch('q_server')
63
- puts hash.inspect
64
- job = Job.new(id, q_server, tube, body, expired_count)
60
+ job = Job.new(id, tube, body, expired_count)
65
61
  return job
66
62
  rescue => ex
67
63
  puts "Server value: #{hash}"
@@ -1,3 +1,3 @@
1
1
  module Allq
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
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.2
4
+ version: 0.1.3
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-11 00:00:00.000000000 Z
11
+ date: 2018-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler