ksconnect 0.1.4 → 0.1.6

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: 01bb45ec16d68199879715b17d8926ba15a23f5d
4
- data.tar.gz: 0b62b79b1bf8d5b9deaa7aeb3aac0b85844486df
3
+ metadata.gz: e06a4a726ae9d277d8c455a9091a5720999d955e
4
+ data.tar.gz: 86b4fde365fbc5b5d4b9a57325920dee13749b71
5
5
  SHA512:
6
- metadata.gz: ec46f07360b655b7fb433d56f73b6d7c51adcfaad60c2db91577449c38de641aa4ed4eeb0db37708508ab78757a06211882197e72d872a7dc2ada76212e75ad2
7
- data.tar.gz: 55743f59b294f8f6d2336bca125019867d29efbfb7d80edfa982a16c5ce470c53b9aa08593912c93edd8e62c64d1479eb4e99c75ca4b59ddf7344057769c1f3a
6
+ metadata.gz: e83a4b54c544587f3b7390f22ac1fc690d0e9ae19884454792ec56ee48ccf82357751bf2371c920e20e755f91db57a7140a216435476e4f1c686501e06d8c34d
7
+ data.tar.gz: 58bd856484abb32f1a18e4112b5519e1373d6de0a6c012e92a6bde957d7afdc60b9521412a6be620780e1e0f41cdfad4cd5eb196d5c0437e9e9bc4952dead89f
data/lib/ksconnect.rb CHANGED
@@ -6,6 +6,7 @@ require 'ksconnect/api/plugin/data'
6
6
  require 'ksconnect/api/plugin/domain'
7
7
  require 'ksconnect/helpers'
8
8
  require 'ksconnect/logs'
9
+ require 'thread/pool'
9
10
 
10
11
  class KSConnect
11
12
  include Logs
@@ -26,17 +27,23 @@ class KSConnect
26
27
  @api = KSConnect::API.new(enabled_plugins: plugins, use_helpers: additional_options[:use_helpers])
27
28
  end
28
29
 
30
+ def self.thread_pool
31
+ @@thread_pool ||= Thread.pool(3, 50)
32
+ end
33
+
29
34
  def self.channel(name)
30
35
  Thread.start do
31
36
  begin
32
37
  Redis.new.subscribe(name) do |on|
33
- logger.info "Subscribing to redis channel: #{name}"
34
- on.message do |channel, message|
35
- yield message
38
+ thread_pool.process do
39
+ logger.info "Subscribing to redis channel: #{name}"
40
+ on.message do |_channel, message|
41
+ yield message
42
+ end
43
+ $stdout.flush
36
44
  end
37
- $stdout.flush
38
45
  end
39
- rescue Exception => error
46
+ rescue => error
40
47
  logger.error "#{error} on redis channel #{name}, restarting in 0.5s"
41
48
  logger.error error.backtrace.join("\n")
42
49
  $stdout.flush
@@ -54,11 +54,30 @@ class KSConnect
54
54
  if %w(initialize update teardown).include? msg['request_type']
55
55
  perform_request(msg)
56
56
  else
57
- config.on_push.call(message)
57
+ begin
58
+ result = config.on_push.call(msg)
59
+ update_action(msg["action_uuid"], :done, result) if msg["action_uuid"]
60
+ rescue => e
61
+ update_action(msg["action_uuid"], :failed, "") if msg["action_uuid"]
62
+ raise e
63
+ end
58
64
  end
59
65
  end
60
66
  end
61
67
 
68
+ def update_action(action_id, state, body="")
69
+ raise "Updating action with empty action_id" if action_id.nil? or action_id.empty?
70
+ redis.multi do |redis_transaction|
71
+ redis_transaction.mapped_hmset "kloudsec_data:#{action_id}", {
72
+ plugin_name: @name,
73
+ uuid: action_id,
74
+ state: state,
75
+ response: body,
76
+ }
77
+ redis_transaction.expire "kloudsec_data:#{action_id}", 300
78
+ end
79
+ end
80
+
62
81
  def perform_request(request)
63
82
  request.stringify_keys!
64
83
 
@@ -30,15 +30,15 @@ class KSConnect
30
30
  end
31
31
 
32
32
  def notify(data)
33
- redis.lpush("kloudsec_notifications", data.merge({ domain_name: @name, plugin_name: @plugin_name }))
33
+ redis.lpush("ks:notifications_push", data.merge({ domain_name: @name, plugin_name: @plugin_name }))
34
34
  end
35
35
 
36
36
  def add_issue(issue_type, data)
37
- redis.lpush("kloudsec_issues", data.merge({ domain_name: @name, plugin_name: @plugin_name, issue_type: issue_type, request_type: 'add' }))
37
+ redis.lpush("ks:issues_push", data.merge({ domain_name: @name, plugin_name: @plugin_name, issue_type: issue_type, request_type: 'add' }))
38
38
  end
39
39
 
40
40
  def clear_issue(issue_type)
41
- redis.lpush("kloudsec_issues", { domain_name: @name, plugin_name: @plugin_name, issue_type: issue_type, request_type: 'remove' })
41
+ redis.lpush("ks:issues_push", { domain_name: @name, plugin_name: @plugin_name, issue_type: issue_type, request_type: 'remove' })
42
42
  end
43
43
 
44
44
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ksconnect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Poon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-28 00:00:00.000000000 Z
11
+ date: 2016-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -95,4 +95,3 @@ signing_key:
95
95
  specification_version: 4
96
96
  summary: Connection API for Kloudsec
97
97
  test_files: []
98
- has_rdoc: