blackstack_commons 1.1.5 → 1.1.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 +4 -4
- data/lib/functions.rb +39 -22
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0337fd24c3ed0b509afa863125066dc36469a0cc
|
4
|
+
data.tar.gz: f353fcfd746176001369d25f16813e94de37018c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc5cb6341786d14379c5e7a62609b30506f3ad2601d5dd75cd2aae31792c647ea272c413b1cb7828a54ac53aeb861eca0f3e0475a84210824201cf081905dc44
|
7
|
+
data.tar.gz: fe8ba22903890286afb1618178bdadf41c1fe40e0ff17cfa80647dd836ab8882691d9385f014411cd908c54583ac25674ee3f93fee9bbbf9db73e1415578dd02
|
data/lib/functions.rb
CHANGED
@@ -482,34 +482,51 @@ module BlackStack
|
|
482
482
|
# ssl_verify_mode: you can disabele SSL verification here.
|
483
483
|
# max_channels: this method use lockfiles to prevent an excesive number of API calls from each datacenter. There is not allowed more simultaneous calls than max_channels.
|
484
484
|
# TODO: setup max_simultaneus_calls in the configurtion file.
|
485
|
-
def self.call_post(url, params = {}, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE
|
485
|
+
def self.call_post(url, params = {}, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, max_channels=10)
|
486
486
|
# build the lockfile name
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
487
|
+
x = rand(max_channels.to_i)
|
488
|
+
lockfilename = "./apicall.channel_#{x.to_s}.lock"
|
489
|
+
lockfile = File.open(lockfilename, "w")
|
490
|
+
|
491
491
|
# lock the file
|
492
|
-
|
492
|
+
lockfile.flock(File::LOCK_EX)
|
493
493
|
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
res
|
494
|
+
begin
|
495
|
+
|
496
|
+
# do the call
|
497
|
+
uri = URI(url)
|
498
|
+
ret = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => ssl_verify_mode) do |http|
|
499
|
+
req = Net::HTTP::Post.new(uri)
|
500
|
+
req['Content-Type'] = 'application/json'
|
501
|
+
req.set_form_data(params)
|
502
|
+
#req.body = body if !body.nil?
|
503
|
+
res = http.request req
|
504
|
+
case res
|
505
|
+
when Net::HTTPSuccess then res
|
506
|
+
when Net::HTTPRedirection then BlackStack::Netting::call_post(URI(res['location']), params)
|
507
|
+
else
|
508
|
+
res.error!
|
509
|
+
end
|
507
510
|
end
|
511
|
+
|
512
|
+
# release the file
|
513
|
+
lockfile.flock(File::LOCK_UN)
|
514
|
+
rescue => e
|
515
|
+
# release the file
|
516
|
+
lockfile.flock(File::LOCK_UN)
|
517
|
+
|
518
|
+
# elevo la excepcion
|
519
|
+
raise e
|
520
|
+
else
|
521
|
+
# release the file
|
522
|
+
lockfile.flock(File::LOCK_UN)
|
523
|
+
# elevo la excepcion
|
524
|
+
raise 'Unknown API call error.'
|
525
|
+
ensure
|
526
|
+
# release the file
|
527
|
+
lockfile.flock(File::LOCK_UN)
|
508
528
|
end
|
509
529
|
|
510
|
-
# release the file
|
511
|
-
#lockfile.flock(File::LOCK_UN)
|
512
|
-
|
513
530
|
# return
|
514
531
|
ret
|
515
532
|
end
|