Created
May 23, 2011 08:05
-
-
Save nicholasf/986379 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/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:in
generate'/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:in
block 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:in
encode'/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:in
put'/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:in
put_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:in
msg_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:in
block in do_threaded_dispatch'