Skip to content

Instantly share code, notes, and snippets.

@afiune
Last active August 29, 2015 14:06
Show Gist options
  • Save afiune/bab87a2e5542eb32c20b to your computer and use it in GitHub Desktop.
Save afiune/bab87a2e5542eb32c20b to your computer and use it in GitHub Desktop.
Chef Data Bag POC
salimafiune@afiunechef:~/chef/data_bag_testing
$ cat err_item.log
item383:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item383 - getaddrinfo: nodename nor servname provided, or not known
item91:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item102:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item102 - getaddrinfo: nodename nor servname provided, or not known
item156:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item174:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item259:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item266:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item366:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item366 - getaddrinfo: nodename nor servname provided, or not known
item112:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item117:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item175:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item189:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item185 - getaddrinfo: nodename nor servname provided, or not known
item219:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item235:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item235 - getaddrinfo: nodename nor servname provided, or not known
item276:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item300:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item300 - getaddrinfo: nodename nor servname provided, or not known
item310:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item310 - getaddrinfo: nodename nor servname provided, or not known
item309:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item310 - getaddrinfo: nodename nor servname provided, or not known
item332:10 => I cannot read ../.chef/afiune.pem, which you told me to use to sign requests!
item77:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item87:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item87 - getaddrinfo: nodename nor servname provided, or not known
item93:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item93 - getaddrinfo: nodename nor servname provided, or not known
item111:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item111 - getaddrinfo: nodename nor servname provided, or not known
item115:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item115 - getaddrinfo: nodename nor servname provided, or not known
item136:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item129 - getaddrinfo: nodename nor servname provided, or not known
item182:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item182 - getaddrinfo: nodename nor servname provided, or not known
item194:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item182 - getaddrinfo: nodename nor servname provided, or not known
item193:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item182 - getaddrinfo: nodename nor servname provided, or not known
item214:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item214 - getaddrinfo: nodename nor servname provided, or not known
item267:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item267 - getaddrinfo: nodename nor servname provided, or not known
item315:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item3:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item365:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item365 - getaddrinfo: nodename nor servname provided, or not known
item357:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item365 - getaddrinfo: nodename nor servname provided, or not known
item384:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item384 - getaddrinfo: nodename nor servname provided, or not known
item17:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item9 - getaddrinfo: nodename nor servname provided, or not known
item21:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item148:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item148 - getaddrinfo: nodename nor servname provided, or not known
item206:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item192 - getaddrinfo: nodename nor servname provided, or not known
item244:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item192 - getaddrinfo: nodename nor servname provided, or not known
item271:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item192 - getaddrinfo: nodename nor servname provided, or not known
item328:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item294 - getaddrinfo: nodename nor servname provided, or not known
item339:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item294 - getaddrinfo: nodename nor servname provided, or not known
item338:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item294 - getaddrinfo: nodename nor servname provided, or not known
item361:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item361 - getaddrinfo: nodename nor servname provided, or not known
item364:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item361 - getaddrinfo: nodename nor servname provided, or not known
item394:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item394 - getaddrinfo: nodename nor servname provided, or not known
item395:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item395 - getaddrinfo: nodename nor servname provided, or not known
item396:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item395 - getaddrinfo: nodename nor servname provided, or not known
item26:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item40:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item40 - getaddrinfo: nodename nor servname provided, or not known
item33:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item40 - getaddrinfo: nodename nor servname provided, or not known
item272:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item40 - getaddrinfo: nodename nor servname provided, or not known
item61:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item40 - getaddrinfo: nodename nor servname provided, or not known
item0:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item142:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item94:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item187:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item187 - getaddrinfo: nodename nor servname provided, or not known
item192:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item187 - getaddrinfo: nodename nor servname provided, or not known
item287:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item285:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item294:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item327:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item353:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item351:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item386:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item367 - getaddrinfo: nodename nor servname provided, or not known
item391:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item379 - getaddrinfo: nodename nor servname provided, or not known
item387:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item387 - getaddrinfo: nodename nor servname provided, or not known
item18:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item387 - getaddrinfo: nodename nor servname provided, or not known
item36:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item36 - getaddrinfo: nodename nor servname provided, or not known
item75:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item10:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item171:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item72:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item216:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item252:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item252 - getaddrinfo: nodename nor servname provided, or not known
item212:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item313:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item369:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item369 - getaddrinfo: nodename nor servname provided, or not known
item379:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item369 - getaddrinfo: nodename nor servname provided, or not known
item91:9 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item91 - getaddrinfo: nodename nor servname provided, or not known
item29:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item29 - getaddrinfo: nodename nor servname provided, or not known
item22:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item22 - getaddrinfo: nodename nor servname provided, or not known
item58:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item22 - getaddrinfo: nodename nor servname provided, or not known
item113:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item185:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item269:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item269 - getaddrinfo: nodename nor servname provided, or not known
item317:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item317 - getaddrinfo: nodename nor servname provided, or not known
item356:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item356 - getaddrinfo: nodename nor servname provided, or not known
item9:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item356 - getaddrinfo: nodename nor servname provided, or not known
item53:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item53 - getaddrinfo: nodename nor servname provided, or not known
item4:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item53 - getaddrinfo: nodename nor servname provided, or not known
item314:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item53 - getaddrinfo: nodename nor servname provided, or not known
item124:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item53 - getaddrinfo: nodename nor servname provided, or not known
item126:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item53 - getaddrinfo: nodename nor servname provided, or not known
item220:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item53 - getaddrinfo: nodename nor servname provided, or not known
item234:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item53 - getaddrinfo: nodename nor servname provided, or not known
item137:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item53 - getaddrinfo: nodename nor servname provided, or not known
item283:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item53 - getaddrinfo: nodename nor servname provided, or not known
item342:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item53 - getaddrinfo: nodename nor servname provided, or not known
item367:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item53 - getaddrinfo: nodename nor servname provided, or not known
item385:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item53 - getaddrinfo: nodename nor servname provided, or not known
item286:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item1:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item150:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item368:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item264 - getaddrinfo: nodename nor servname provided, or not known
item209:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item264 - getaddrinfo: nodename nor servname provided, or not known
item264:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item154:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item108:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item238:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item226:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item336:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item380:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item322:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item50:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item186:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item164:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item112:9 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item112 - getaddrinfo: nodename nor servname provided, or not known
item278:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item248:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item298:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item292:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item52:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item320:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item54:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item294:9 => Too many open files - socket(2) for "api.opscode.com" port 443
item318:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item287:9 => I cannot read ../.chef/afiune.pem, which you told me to use to sign requests!
item285:9 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item285 - getaddrinfo: nodename nor servname provided, or not known
item67:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item285 - getaddrinfo: nodename nor servname provided, or not known
item328:9 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item338 - getaddrinfo: nodename nor servname provided, or not known
item301:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item333:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item196:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item313:9 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item313 - getaddrinfo: nodename nor servname provided, or not known
item141:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item385:9 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item385 - getaddrinfo: nodename nor servname provided, or not known
item193:9 => Too many open files - socket(2) for "api.opscode.com" port 443
item255:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item291:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item127:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item338:9 => Too many open files - socket(2) for "api.opscode.com" port 443
item34:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item366:9 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item366 - getaddrinfo: nodename nor servname provided, or not known
item149:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item366 - getaddrinfo: nodename nor servname provided, or not known
item309:9 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item366 - getaddrinfo: nodename nor servname provided, or not known
item188:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item366 - getaddrinfo: nodename nor servname provided, or not known
item170:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item243:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item314:9 => Too many open files - socket(2) for "api.opscode.com" port 443
item249:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item340:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item208:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item394:9 => Too many open files - socket(2) for "api.opscode.com" port 443
item281:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item329:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item73:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item225:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item230:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known Chef-11.14.6 ruby-2.1.2
item397:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item326:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item334:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item346:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item204:10 => Too many open files - socket(2) for "api.opscode.com" port 443
item65:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item231:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item205:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item18:9 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item18 - getaddrinfo: nodename nor servname provided, or not known
item137:9 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item234 - getaddrinfo: nodename nor servname provided, or not known
item330:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item234 - getaddrinfo: nodename nor servname provided, or not known
item234:9 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing/item234 - getaddrinfo: nodename nor servname provided, or not known
item114:10 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
item4:9 => Error connecting to https://api.opscode.com/organizations/afiune/data/testing - getaddrinfo: nodename nor servname provided, or not known
salimafiune@afiunechef:~/chef/data_bag_testing
$ ruby parallel_insertions.rb
Data bag testing already exist. We will destroy it! (5 sec)
Data bag testing has 0 items.
Inserting ...
Waiting for 936 thread(s) to finish...
[2014-09-24T11:41:03-04:00] ERROR: Connection refused connecting to https://api.opscode.com/organizations/afiune/data/testing, retry 1/5
[2014-09-24T11:41:04-04:00] ERROR: Connection refused connecting to https://api.opscode.com/organizations/afiune/data/testing, retry 1/5
[2014-09-24T11:41:04-04:00] ERROR: Connection refused connecting to https://api.opscode.com/organizations/afiune/data/testing, retry 1/5
[2014-09-24T11:41:04-04:00] ERROR: Connection refused connecting to https://api.opscode.com/organizations/afiune/data/testing, retry 1/5
Data bag testing has 800 items.
salimafiune@afiunechef:~/chef/data_bag_testing
$ knife data bag show testing|wc -l
800
salimafiune@afiunechef:~/chef/data_bag_testing
$ knife data bag show testing item432
content: This is the content of item432
id: item432
salimafiune@afiunechef:~/chef/data_bag_testing
$ knife data bag show testing item2
content: This is the content of item2
id: item2
salimafiune@afiunechef:~/chef/data_bag_testing
$ knife data bag show testing item799
content: This is the content of item799
id: item799
salimafiune@afiunechef:~/chef/data_bag_testing
$
#!/usr/bin/env ruby
require 'chef'
# Testing data bag name
dbag = "testing"
# Number of insertions
N = 800
# Error log file
err_file = 'err_item.log'
# Clean Error Log File
File.delete(err_file) if File.exist?(err_file)
# Loading knife configuration
begin
Chef::Config.from_file("../.chef/knife.rb")
rescue Exception => e
puts "Error: Please validate that the knife.rb path is correct."
exit(2)
end
# Ensure that the testing bag is a brand new bag
begin
bag = Chef::DataBag.new
bag.name(dbag)
bag.create
rescue Exception => e
puts "WARNING: Data bag #{dbag} already exist. We will destroy it! (5 sec)"
sleep 5
bag.destroy
retry
end
# We collect the number of items BEFORE the insertion
before = Chef::DataBag.load(dbag)
puts "Data bag #{dbag} has #{before.size} items."
# Lets wrinte 100 items in parallel..
puts "Inserting #{N} items..."
N.times do |i|
# puts "Inserting item#{i}"
Thread.new do
Thread.current["i"] = i
Thread.current["tries"] ||= 10
begin
item = Chef::DataBagItem.new
item.data_bag(dbag)
item['id'] = "item#{Thread.current["i"]}"
item['content'] = "This is the content of item#{Thread.current["i"]}"
item.save
rescue Exception => e
File.open(err_file, 'a') do |f|
f << "item#{Thread.current["i"]}:#{Thread.current["tries"]} => #{e.message}\n"
end
sleep 1
retry unless (Thread.current["tries"] -= 1).zero?
end
end
end
# WAIT! Yeah We gotta wait for the threads
puts "Waiting for #{Thread.list.size} thread(s) to finish..."
sleep 1 while Thread.list.size > 2
# Now AFTER the process has finished
after = Chef::DataBag.load(dbag)
puts "Data bag #{dbag} has #{after.size} items."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment