Skip to content

Instantly share code, notes, and snippets.

@nicholasf
Created May 23, 2011 08:05
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/986379 to your computer and use it in GitHub Desktop.
Save nicholasf/986379 to your computer and use it in GitHub Desktop.
#basically, my process def wants to keep iterating through archive_catalog_integrations, but it also wants the participant to keep
#adding items to process in this cursor block
cursor do
concurrent_iterator :on_field => 'archive_catalog_integrations', :to_f => "archive_catalog_integration_id" do
participant :ref => 'download_and_convert_catalog_tree'
end
rewind :if => '${archive_catalog_integrations.any?}'
end
#the participant, very messy - still working it out
engine.register_participant 'download_and_convert_catalog_tree' do |workitem|
archive_catalog_integration = ArchiveCatalogIntegration.find(workitem.fields['archive_catalog_integration_id'])
workitem.fields['archive_catalog_integrations'].delete(archive_catalog_integration)
archive = archive_catalog_integration.archive
file = "#{$catalogs_xml_dir}#{archive.slug}/#{archive_catalog_integration.label}.xml"
#does a parent exist for this catalog?
parent_id = workitem.fields['children_to_parents'][archive_catalog_integration.url]
`curl -o #{file} --compressed "#{archive_catalog_integration.url}"`
label_hash = Nesstar::RDF::Parser.parse_catalog("#{file}")
catalog = ArchiveCatalog.create!(:title => label_hash[:label], :archive_catalog_integration => archive_catalog_integration)
if parent_id
node = ArchiveCatalogNode.create!(:archive_catalog => catalog, :parent_id => parent_id)
else
node = ArchiveCatalogNode.create!(:archive_catalog => catalog)
end
children_file = "#{$catalogs_xml_dir}#{archive.slug}/#{archive_catalog_integration.label}@children.xml"
`curl -o #{children_file} --compressed "#{archive_catalog_integration.url}@children"`
children = Nesstar::RDF::Parser.parse_catalog_children("#{children_file}")
for child in children
if child[:resource] =~ /fStudy/
study = Study.find_by_about(child[:resource])
archive_study = study.for_archive(archive)
node = ArchiveCatalogNode.create!(:archive_study => archive_study, :parent => node, :catalog_position => child[:position])
else
integration = ArchiveCatalogIntegration.create(:archive => archive, :url => child[:resource])
workitem.fields['archive_catalog_integrations'] << integration.id
workitem.fields['children_to_parents'][integration.url]= node.id #store the parent for future association
end
end
# workitem.fields['Catalogs_oustanding'] <<
end
@nicholasf
Copy link
Author

<ArgumentError: wrong number of arguments (2 for 1)>

/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.7/lib/active_support/core_ext/object/to_json.rb:19:in to_json' /Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/json_pure-1.5.1/lib/json/common.rb:212:ingenerate'
/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/json_pure-1.5.1/lib/json/common.rb:212:in generate' /Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/rufus-json-0.2.7/lib/rufus/json.rb:37:inblock in module:Json'
/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/rufus-json-0.2.7/lib/rufus/json.rb:124:in call' /Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/rufus-json-0.2.7/lib/rufus/json.rb:124:inencode'
/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/rufus-json-0.2.7/lib/rufus/json.rb:171:in dup' /Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/rufus-cloche-0.1.21/lib/rufus/cloche.rb:82:input'
/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruote-0a22f137c90b/lib/ruote/storage/fs_storage.rb:68:in put' /Users/nicholas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruote-0a22f137c90b/lib/ruote/storage/base.rb:70:input_msg'
/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruote-0a22f137c90b/lib/ruote/receiver/base.rb:44:in receive' /Users/nicholas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruote-0a22f137c90b/lib/ruote/receiver/base.rb:97:inreply_to_engine'
/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruote-0a22f137c90b/lib/ruote/part/block_participant.rb:80:in consume' /Users/nicholas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruote-0a22f137c90b/lib/ruote/svc/dispatch_pool.rb:74:indo_dispatch'
/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruote-0a22f137c90b/lib/ruote/svc/dispatch_pool.rb:101:in `block in do_threaded_dispatch'
...

-- msg --
_id : "56840!2159496620!2011-05-23!1306138979.799032!095"
rev : 0
action : "dispatch"
fei : "0_1_2!143b54fa371c454526d0b7e09a127c07!20110523-bomozameze"
participant : ["Ruote::BlockParticipant", {"on_workitem"=>"proc do |workitem|\n dataset_urls = []\n workitem.fields['studies_to_download'] ||= []\n\n queries = ArchiveStudyQuery.all\n\n for query in queries\n query.save!\n query_response_file = "#{$xml_dir}query_response
#{Time.now.to_i}.xml"\n\n curl -o \#{query_response_file} --compressed \"\#{query.query}\"\n handler = Nesstar::QueryResponseParser.new(query_response_file)\n\n for url in handler.datasets\n ddi_id = url.split(".").last\n #the validations on the object ensure we don't duplicate the object (archive + query must be unique, url can repeat)\n pre_existing = ArchiveStudyIntegration.find_by_archive_id_and_ddi_id(query.archive.id, ddi_id)\n unless pre_existing\n ArchiveStudyIntegration.create!(:ddi_id => ddi_id, :archive => query.archive,\n :archive_study_query => query, :user_id => query.id)\n end\n end\n end\n \n catalogs = ArchiveCatalogIntegration.all\n \n for catalog in catalogs\n archive = catalog.archive\n file = "#{$catalogs_xml_dir}#{archive.slug}/#{catalog.label}@datasets.xml" #request all datasets referenced by this catalog\n\n curl -o \#{file} --compressed \"\#{catalog.url}@datasets\"\n studies_in_catalog = Nesstar::RDF::Parser.parse_catalog_children("#{file}")\n \n for study in studies_in_catalog\n ddi_id = study[:resource].split(".").last\n ArchiveStudyIntegration.create!(:ddi_id => ddi_id, :archive => catalog.archive, :archive_catalog_integration_id => catalog.id)\n end\n end\n \n workitem.fields['studies_to_download'] = Set.new\n ArchiveStudyIntegration.all.each do |integration|\n workitem.fields['studies_to_download'] << integration.ddi_id\n end\n end"}]
participant_name : "load_study_integrations"
put_at : "2011-05-23 08:22:59.799062 UTC"
type : "msgs"
workitem : {"fields"=>{"result"=>nil, "children_to_parents"=>{}, "archive_catalog_integrations"=>[1, 3, 5, 2, 4], "params"=>{"ref"=>"load_study_integrations"}, "dispatched_at"=>"2011-05-23 08:22:59.804481 UTC", "studies_to_download"=>#<Set: {"00102-f", "00102-h", "00102-m", "00115", "00103", "00349", "00601", "00602", "00822-c02", "00822-p01", "00822-c01", "00603", "00604", "00822-p02", "00967", "00986", "01159"}>}, "wf_name"=>"convert_datasets", "wf_revision"=>nil, "fei"=>{"engine_id"=>"engine", "wfid"=>"20110523-bomozameze", "subid"=>"143b54fa371c454526d0b7e09a127c07", "expid"=>"0_1_2"}, "participant_name"=>"load_study_integrations"}
-- . --

rake aborted!
wrong number of arguments (2 for 1)

(See full trace by running task with --trace)
andromeda:ada-cms nicholas$

@nicholasf
Copy link
Author

/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.7/lib/active_support/core_ext/object/to_json.rb:19:in to_json' /Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/json_pure-1.5.1/lib/json/common.rb:212:ingenerate'
/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/json_pure-1.5.1/lib/json/common.rb:212:in generate' /Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/rufus-json-0.2.7/lib/rufus/json.rb:37:inblock in module:Json'
/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/rufus-json-0.2.7/lib/rufus/json.rb:124:in call' /Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/rufus-json-0.2.7/lib/rufus/json.rb:124:inencode'
/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/rufus-json-0.2.7/lib/rufus/json.rb:171:in dup' /Users/nicholas/.rvm/gems/ruby-1.9.2-p0/gems/rufus-cloche-0.1.21/lib/rufus/cloche.rb:82:input'
/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruote-0a22f137c90b/lib/ruote/storage/fs_storage.rb:68:in put' /Users/nicholas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruote-0a22f137c90b/lib/ruote/storage/base.rb:70:input_msg'
/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruote-0a22f137c90b/lib/ruote/svc/error_handler.rb:111:in handle' /Users/nicholas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruote-0a22f137c90b/lib/ruote/svc/error_handler.rb:51:inmsg_handle'
/Users/nicholas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruote-0a22f137c90b/lib/ruote/svc/dispatch_pool.rb:104:in rescue in block in do_threaded_dispatch' /Users/nicholas/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruote-0a22f137c90b/lib/ruote/svc/dispatch_pool.rb:99:inblock in do_threaded_dispatch'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment