vayacondios-client 0.1.7 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/vayacondios/client/itemset.rb +37 -1
  2. metadata +4 -4
@@ -1,3 +1,4 @@
1
+ require 'gorillib/logger/log'
1
2
  require 'net/http'
2
3
  require 'multi_json'
3
4
 
@@ -29,7 +30,6 @@ class Vayacondios
29
30
  execute_request(_req(:remove, ary, organization, topic, id))
30
31
  end
31
32
 
32
-
33
33
  private
34
34
 
35
35
  def execute_request req
@@ -68,5 +68,41 @@ class Vayacondios
68
68
  end
69
69
  end
70
70
  end
71
+
72
+ # Subclasses should implement the remove_items(arr) and
73
+ # add_items(arr) methods, both of which will be called with arrays
74
+ # when the items in an itemset change. The run method polls the
75
+ # provided itemset at a specified interval and calls these methods
76
+ # appropriately.
77
+ class ItemSetListener
78
+ POLL_WAIT_SEC=2
79
+
80
+ def initialize itemset, poll_wait_sec = POLL_WAIT_SEC
81
+ @itemset = itemset
82
+ @items = []
83
+ @poll_wait_sec = poll_wait_sec
84
+ end
85
+
86
+ def setup() end
87
+ def teardown() end
88
+
89
+ def run
90
+ setup
91
+ loop do
92
+ new_items = @itemset.fetch || []
93
+
94
+ Log.debug "currently configured: #{@items.inspect}"
95
+ Log.debug "new items: #{new_items.inspect}"
96
+
97
+ add_items(new_items - @items)
98
+ remove_items(@items - new_items)
99
+
100
+ @items = new_items
101
+
102
+ sleep @poll_wait_sec
103
+ end
104
+ teardown
105
+ end
106
+ end
71
107
  end
72
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vayacondios-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-03-08 00:00:00.000000000 Z
15
+ date: 2013-04-02 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: configliere
@@ -140,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
140
  version: '0'
141
141
  segments:
142
142
  - 0
143
- hash: -172339811047827966
143
+ hash: 1788839692772857414
144
144
  required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  none: false
146
146
  requirements:
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  segments:
151
151
  - 0
152
- hash: -172339811047827966
152
+ hash: 1788839692772857414
153
153
  requirements: []
154
154
  rubyforge_project:
155
155
  rubygems_version: 1.8.25