Skip to content

Instantly share code, notes, and snippets.

@nicholasf
Created March 30, 2011 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholasf/893996 to your computer and use it in GitHub Desktop.
Save nicholasf/893996 to your computer and use it in GitHub Desktop.
concurrent_iterator :on_field => 'variable_urls', :to_f => "variable_url" do
participant :ref => 'convert_variable'
end
engine.register_participant 'convert_variable' do |workitem|
mutex = Nesstar::Mutexer.available
begin
mutex = Nesstar::Mutexer.available
sleep 2 if mutex.nil?
end while mutex.nil?
@@curl_count += 1
puts "found a free curl conn #{@@curl_count}"
#we looks for a study's variables
variable_url = workitem.fields['variable_url']
var_file_name = variable_url.split(".").last
`curl -o #{$xml_dir}#{var_file_name} --compressed "#{variable_url}"`
variables_list = RDF::Parser.parse_variables("#{$xml_dir}/#{var_file_name}")
variables_list.each do |var_hash|
variable = Variable.store_with_fields(var_hash)
end
mutex.unlock
#....
end
class Mutexer
LIMIT = 10
CURL_MUTEXES = []
[0..LIMIT].each {CURL_MUTEXES << Mutex.new}
def self.available
for mutex in CURL_MUTEXES
available = mutex if not mutex.locked?
break if available
end
available.lock if available
puts "**** \n\n offering a mutex" if available
available
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment