hotdog 0.0.4 → 0.0.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: 933d32781a29b749befc75434934913bc85ca09a
4
- data.tar.gz: ae79146d62e2da1110246485559571d8d43475a4
3
+ metadata.gz: 87916b1a0fd595019d2e97021bd753cc95ea39ad
4
+ data.tar.gz: 7f525b438a8ea90084f1a22b6277e863f32061be
5
5
  SHA512:
6
- metadata.gz: f5c3b0eb31180b6057bb3a6da9c077fbef40d79eb28ab46215b5ae60471df254c73011003f5795e07d2dbda1594326db25c8acdacad4e8e4425dbf54fef855ab
7
- data.tar.gz: 7791194153534266e7768c0a1cd96d391fd274aab72a4e93b9ea6776515e0fa1b45b628f4e65ac84c8b9fab5d3b3d6fe73341f8b8ec47c054c1c3f61c88ef4a3
6
+ metadata.gz: dbc182c9a25be6d3116065930968379095b0248cbd4bc386f26f6c4860d9e3ed73322ae298e44192e5a16a3cbb5401ec08490fe2f7c717fa480d321e75011df6
7
+ data.tar.gz: 3a8d9bc7ce921d4f9fbd2ffde40ae2468119a5d082c32551ae4aa494df969dca4757f00ac9fa25a6e339deb1ca8d2fe060ae8a174420b124fe569ba757e8f650
data/README.md CHANGED
@@ -75,6 +75,36 @@ $ hotdog search availability-zone:us-east-1b and 'name:web-*'
75
75
  i-03cb56ed
76
76
  ```
77
77
 
78
+
79
+ ## Expression
80
+
81
+ Acceptable expressions in pseudo BNF.
82
+
83
+ ```
84
+ expression: binary_expression
85
+ | term
86
+
87
+ binary_expression: term "&&" term
88
+ | term "||" term
89
+ | term "and" term
90
+ | term "or" term
91
+
92
+ unary_expression: '!' expression
93
+ | '~' expression
94
+ | "not" expression
95
+
96
+ term: unary_expression
97
+ | atom
98
+
99
+ atom: '(' expression ')'
100
+ | IDENTIFIER separator ATTRIBUTE
101
+ | IDENTIFIER
102
+
103
+ separator: ':'
104
+ | '='
105
+ ```
106
+
107
+
78
108
  ## Contributing
79
109
 
80
110
  1. Fork it ( https://github.com/yyuu/hotdog/fork )
@@ -14,7 +14,7 @@ module Hotdog
14
14
  @optparse = OptionParser.new
15
15
  @options = {
16
16
  environment: "default",
17
- minimum_expiry: 28800, # 8 hours
17
+ minimum_expiry: 3600, # 1 hour
18
18
  random_expiry: 604800, # 7 days
19
19
  fixed_string: false,
20
20
  force: false,
@@ -22,7 +22,7 @@ module Hotdog
22
22
  headers: false,
23
23
  listing: false,
24
24
  logger: Logger.new(STDERR),
25
- max_time: 30,
25
+ max_time: 10,
26
26
  api_key: ENV["DATADOG_API_KEY"],
27
27
  application_key: ENV["DATADOG_APPLICATION_KEY"],
28
28
  print0: false,
@@ -104,12 +104,12 @@ module Hotdog
104
104
  EOS
105
105
  result = hosts.map { |host_id, host_name|
106
106
  update_host_tags(host_name, @options.dup)
107
- logger.debug("get_hosts_q3()")
108
107
  @get_hosts_q3 ||= @db.prepare(<<-EOS)
109
108
  SELECT DISTINCT tags.name FROM hosts_tags
110
109
  INNER JOIN tags ON hosts_tags.tag_id = tags.id
111
110
  WHERE hosts_tags.host_id = ?;
112
111
  EOS
112
+ logger.debug("get_hosts_q3()")
113
113
  tag_names = @get_hosts_q3.execute(host_id).map { |row| row.first }
114
114
  tag_names.each do |tag_name|
115
115
  fields << tag_name unless fields.index(tag_name)
@@ -136,6 +136,9 @@ module Hotdog
136
136
  end
137
137
 
138
138
  def update_hosts(options={})
139
+ if suspended?
140
+ return
141
+ end
139
142
  @db.transaction do
140
143
  if not options[:force]
141
144
  # Update host list on every expirations to update frequently.
@@ -159,6 +162,7 @@ module Hotdog
159
162
  raise("dog.search(%s) returns (%s: %s)" % ["hosts:".inspect, code.inspect, result.inspect])
160
163
  end
161
164
 
165
+ resume_host_tags
162
166
  execute(<<-EOS % result["results"]["hosts"].map { "LOWER(?)" }.join(", "), result["results"]["hosts"])
163
167
  DELETE FROM hosts_tags WHERE host_id NOT IN
164
168
  ( SELECT id FROM hosts WHERE LOWER(name) IN ( %s ) );
@@ -181,6 +185,9 @@ module Hotdog
181
185
  end
182
186
 
183
187
  def update_tags(options={})
188
+ if suspended?
189
+ return
190
+ end
184
191
  @db.transaction do
185
192
  resume_host_tags
186
193
 
@@ -191,11 +198,11 @@ module Hotdog
191
198
  logger.debug("update_tags_q1()")
192
199
  hosts = @update_tags_q1.execute().map { |row| row.first }
193
200
  else
194
- logger.debug("update_tags_q2()")
195
201
  @update_tags_q2 ||= @db.prepare(<<-EOS)
196
202
  SELECT DISTINCT hosts_tags.host_id FROM hosts_tags
197
203
  WHERE hosts_tags.expires_at < ?;
198
204
  EOS
205
+ logger.debug("update_tags_q2()")
199
206
  hosts = @update_tags_q2.execute(Time.new.to_i)
200
207
  end
201
208
  hosts.each do |host_id|
@@ -224,8 +231,10 @@ module Hotdog
224
231
  def suspend_host_tags()
225
232
  @suspended = true
226
233
  @suspend_host_tags_q1 ||= @db.prepare("INSERT OR IGNORE INTO hosts (name) VALUES (?);")
234
+ logger.debug("suspend_host_tags_q1(%s)" % [EMPTY_HOST_NAME.inspect])
227
235
  @suspend_host_tags_q1.execute(EMPTY_HOST_NAME)
228
236
  @suspend_host_tags_q2 ||= @db.prepare("INSERT OR IGNORE INTO tags (name, value) VALUES (?, ?);")
237
+ logger.debug("suspend_host_tags_q2(%s, %s)" % [EMPTY_TAG_NAME.inspect, EMPTY_TAG_VALUE.inspect])
229
238
  @suspend_host_tags_q2.execute(EMPTY_TAG_NAME, EMPTY_TAG_VALUE)
230
239
  @suspend_host_tags_q3 ||= @db.prepare(<<-EOS)
231
240
  INSERT OR REPLACE INTO hosts_tags (host_id, tag_id, expires_at)
@@ -233,6 +242,7 @@ module Hotdog
233
242
  ( SELECT id FROM hosts WHERE name = ?) AS host,
234
243
  ( SELECT id FROM tags WHERE name = ? AND value = ? ) AS tag;
235
244
  EOS
245
+ logger.debug("suspend_host_tags_q3(%s, %s, %s, %s)" % [EMPTY_EXPIRES_AT.inspect, EMPTY_HOST_NAME.inspect, EMPTY_TAG_NAME.inspect, EMPTY_TAG_VALUE.inspect])
236
246
  @suspend_host_tags_q3.execute(EMPTY_EXPIRES_AT, EMPTY_HOST_NAME, EMPTY_TAG_NAME, EMPTY_TAG_VALUE)
237
247
  end
238
248
 
@@ -241,10 +251,15 @@ module Hotdog
241
251
  DELETE FROM hosts_tags
242
252
  WHERE host_id IN ( SELECT id FROM hosts WHERE name = ? ) AND tag_id IN ( SELECT id FROM tags WHERE name = ? AND value = ? );
243
253
  EOS
254
+ logger.debug("resume_host_tags_q1(%s, %s, %s)" % [EMPTY_HOST_NAME.inspect, EMPTY_TAG_NAME.inspect, EMPTY_TAG_VALUE.inspect])
244
255
  @resume_host_tags_q1.execute(EMPTY_HOST_NAME, EMPTY_TAG_NAME, EMPTY_TAG_VALUE)
245
256
  end
246
257
 
247
258
  def update_host_tags(host_name, options={})
259
+ if suspended?
260
+ # stop updating if the `update_host_tags` has already been suspended
261
+ return
262
+ end
248
263
  if Integer === host_name
249
264
  host_id = host_name
250
265
  @update_host_tags_q1 ||= @db.prepare("SELECT name FROM hosts WHERE id = ? LIMIT 1;")
@@ -169,11 +169,13 @@ module Hotdog
169
169
  if left_values.empty?
170
170
  []
171
171
  else
172
- (left_values & @right.evaluate(environment)).uniq
172
+ right_values = @right.evaluate(environment)
173
+ (left_values & right_values)
173
174
  end
174
175
  when "||", "|", /\Aor\z/i
175
176
  left_values = @left.evaluate(environment)
176
- (left_values | @right.evaluate(environment)).uniq
177
+ right_values = @right.evaluate(environment)
178
+ (left_values | right_values).uniq
177
179
  else
178
180
  raise(SyntaxError.new("unknown binary operator: #{@op}"))
179
181
  end
@@ -4,7 +4,7 @@ module Hotdog
4
4
  module Commands
5
5
  class Update < BaseCommand
6
6
  def run(args=[])
7
- options[:force] = true
7
+ options[:force] = true unless ARGV.include?("--no-force")
8
8
  if 0 < args.length
9
9
  args.each do |host_name|
10
10
  update_host_tags(host_name, @options.dup)
@@ -1,3 +1,3 @@
1
1
  module Hotdog
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotdog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yamashita Yuu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-31 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler