allq 0.3.5 → 0.3.6

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: 89cc071fa78a00b3bbda7e21cacfc4cbe20d992c
4
- data.tar.gz: d0aecf251d0587c8e0d01f2bdf39099a82f3891b
3
+ metadata.gz: 780c18967adea5a53a4b82b52b4af5ac6dbfe977
4
+ data.tar.gz: a079b08e7911d7b503169b2f90a4e513cec62738
5
5
  SHA512:
6
- metadata.gz: 43cb8d3c2614a46e6e5167613381040487b55aeb6df5cc6e50d4fc705456a5b4c112c9d3c3f8f4bdec17c02c0e40f25edfba12e3a151b47c0667784b873b9f5b
7
- data.tar.gz: 0ba32f6101c5a53402697c857d2b2783af11847272b8f9ac65a4a0ae592a71bf7e7472705b3fa509b785a0869f12ded5d049171b2702a734eb0aca9f37dc95b2
6
+ metadata.gz: '07894d27ff1389c1db25779fe0c09253114df0db3e8c4587bbd25604f232f9a9fe944a30f7b5e38affdc11a451c6770bdd02ceb891bbe6a105df1a27de9c7ce8'
7
+ data.tar.gz: d8b782e4bbcdf622d6379836f0bda07396ed3d47c9126565d6283d04d9ce1e4a38a15c3615d4e5895293bc6798868fb1903e0fc824c1fe83048de0c652901ccd
@@ -24,13 +24,21 @@ class AllQ
24
24
  data
25
25
  end
26
26
 
27
- def send_hash_as_json(data_hash)
27
+ def send_hash_as_json(data_hash, ignore_failure = false)
28
28
  transmit_data = data_hash.to_json
29
29
  result = nil
30
30
  puts "transmitting data: #{transmit_data}" if ALLQ_DEBUG_DATA
31
- @connection.transmit(transmit_data) do |response|
32
- result = response
31
+ if ignore_failure
32
+ @connection.socat(transmit_data) do |response|
33
+ result = response
34
+ end
35
+ results = "{}" if results.to_s == ""
36
+ else
37
+ @connection.transmit(transmit_data) do |response|
38
+ result = response
39
+ end
33
40
  end
41
+
34
42
  result
35
43
  end
36
44
 
@@ -5,7 +5,7 @@ class AllQ
5
5
  job_id = data[:job_id]
6
6
 
7
7
  send_data = base_send(job_id)
8
- response = send_hash_as_json(send_data)
8
+ response = send_hash_as_json(send_data, true)
9
9
  result = rcv(response)
10
10
  return result
11
11
  end
@@ -5,7 +5,7 @@ class AllQ
5
5
  job_id = data[:job_id]
6
6
 
7
7
  send_data = base_send(job_id)
8
- response = send_hash_as_json(send_data)
8
+ response = send_hash_as_json(send_data, true)
9
9
  result = rcv(response)
10
10
  return JSON.parse(result)
11
11
  end
@@ -5,7 +5,7 @@ class AllQ
5
5
  job_id = data[:job_id]
6
6
 
7
7
  send_data = base_send(job_id)
8
- response = send_hash_as_json(send_data)
8
+ response = send_hash_as_json(send_data, true)
9
9
  rcv(response)
10
10
  end
11
11
 
@@ -6,7 +6,7 @@ class AllQ
6
6
  tube = data[:tube]
7
7
 
8
8
  send_data = base_send(tube)
9
- response = send_hash_as_json(send_data)
9
+ response = send_hash_as_json(send_data, true)
10
10
  rcv(response)
11
11
  end
12
12
 
@@ -5,7 +5,7 @@ class AllQ
5
5
  job_id = data[:job_id]
6
6
  delay = data[:delay] || 0
7
7
  send_data = base_send(job_id, delay)
8
- response = send_hash_as_json(send_data)
8
+ response = send_hash_as_json(send_data, true)
9
9
  result = rcv(response)
10
10
  return result["release"] && result["release"]["job_id"]
11
11
  end
@@ -7,7 +7,7 @@ class AllQ
7
7
  def snd(data)
8
8
  send_data = base_send(data)
9
9
  @breakout = data ? data[:breakout].to_s == "true" : false
10
- response = send_hash_as_json(send_data)
10
+ response = send_hash_as_json(send_data, true)
11
11
  rcv(response)
12
12
  end
13
13
 
@@ -5,7 +5,7 @@ class AllQ
5
5
  job_id = data[:job_id]
6
6
 
7
7
  send_data = base_send(job_id)
8
- response = send_hash_as_json(send_data)
8
+ response = send_hash_as_json(send_data, true)
9
9
  result = rcv(response)
10
10
  return result["touch"] && result["touch"]["job_id"]
11
11
  end
@@ -30,11 +30,28 @@ class AllQ
30
30
  #
31
31
  def initialize(address = '')
32
32
  @address = address || _host_from_env
33
+ @mutex = Mutex.new
33
34
  establish_connection
34
35
  rescue
35
36
  _raise_not_connected!
36
37
  end
37
38
 
39
+ def socat(command, options={}, &block)
40
+ send_string = command.to_s
41
+ if send_string.include?("'")
42
+ puts "Single quotes not allow in JSON. This will probably error."
43
+ end
44
+ res = call_socat(send_string)
45
+ _raise_not_connected if res.include?("Connection refused")
46
+ yield block.call(res)
47
+ end
48
+
49
+ def call_socat(data)
50
+ cmd_string = "echo '#{data}' | socat - tcp4-connect:#{@address}"
51
+ output = `#{cmd_string}`
52
+ return output
53
+ end
54
+
38
55
  # Send commands to allq server via connection.
39
56
  #
40
57
  # @param [String] command AllQ command
@@ -46,29 +63,25 @@ class AllQ
46
63
  #
47
64
  def transmit(command, options={}, &block)
48
65
  _with_retry(options[:retry_interval], options[:init]) do
49
- send_string = command.to_s
50
- if send_string.include?("'")
51
- puts "Single quotes not allow in JSON. This will probably error."
66
+ @mutex.synchronize do
67
+ _raise_not_connected! unless @connection && !@connection.closed?
68
+ @connection.puts(command.to_s)
69
+ res = @connection.readline
70
+ yield block.call(res)
52
71
  end
53
- res = call_socat(send_string)
54
- _raise_not_connected if res.include?("Connection refused")
55
- yield block.call(res)
56
72
  end
57
73
  end
58
74
 
59
- def call_socat(data)
60
- cmd_string = "echo '#{data}' | socat - tcp4-connect:#{address}"
61
- output = `#{cmd_string}`
62
- return output
63
- end
64
-
65
75
  # Close connection with allq server.
66
76
  #
67
77
  # @example
68
78
  # @conn.close
69
79
  #
70
80
  def close
71
- # no_op
81
+ if @connection
82
+ @connection.close
83
+ @connection = nil
84
+ end
72
85
  end
73
86
 
74
87
  # Returns string representation of job.
@@ -77,7 +90,7 @@ class AllQ
77
90
  # @conn.inspect
78
91
  #
79
92
  def to_s
80
- "#<AllQ::Connection address=#{address}>"
93
+ "#<AllQ::Connection host=#{host.inspect} port=#{port.inspect}>"
81
94
  end
82
95
  alias :inspect :to_s
83
96
 
@@ -91,6 +104,11 @@ class AllQ
91
104
  # establish_connection('localhost:3005')
92
105
  #
93
106
  def establish_connection
107
+ @address = address.first if address.is_a?(Array)
108
+ match = address.split(':')
109
+ @host, @port = match[0], Integer(match[1] || DEFAULT_PORT)
110
+
111
+ @connection = TCPSocket.new @host, @port
94
112
  end
95
113
 
96
114
  private
@@ -116,6 +134,7 @@ class AllQ
116
134
  # @param [Integer] tries The maximum number of attempts to reconnect
117
135
  def _reconnect(original_exception, retry_interval, tries=MAX_RETRIES)
118
136
  close
137
+ establish_connection
119
138
  rescue Errno::ECONNREFUSED
120
139
  tries -= 1
121
140
  if tries.zero?
@@ -59,10 +59,6 @@ class AllQ
59
59
  }
60
60
  end
61
61
 
62
- def reload_client
63
- @client.reload!
64
- end
65
-
66
62
  def self.new_from_hash(hash, client)
67
63
  begin
68
64
  id = hash.fetch('job_id')
@@ -1,3 +1,3 @@
1
1
  module Allq
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason