From 227668f07a50c018eb7521f4c1d6170277c4c543 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Fri, 10 May 2019 14:26:19 -0500 Subject: [PATCH] Don't start workflow until after save Fixes a race condition where goobiWF was starting, but couldn't get source_id --- app/services/registration_service.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/services/registration_service.rb b/app/services/registration_service.rb index c2fa0e71ff..389f20861f 100644 --- a/app/services/registration_service.rb +++ b/app/services/registration_service.rb @@ -114,14 +114,16 @@ def register_object(params = {}) build_desc_metadata_from_label(new_item, label) if metadata_source == 'label' RefreshMetadataAction.run(new_item) if seed_desc_metadata - workflow_priority = params[:workflow_priority] ? params[:workflow_priority].to_i : 0 - initiate_workflow(workflows: Array(params[:initiate_workflow]), item: new_item, priority: workflow_priority) - new_item.class.ancestors.select { |x| x.respond_to?(:to_class_uri) && x != ActiveFedora::Base }.each do |parent_class| new_item.add_relationship(:has_model, parent_class.to_class_uri) end new_item.save + + # Once we save, then it's safe to start any workflows. Otherwise there could be a race condition + workflow_priority = params[:workflow_priority] ? params[:workflow_priority].to_i : 0 + initiate_workflow(workflows: Array(params[:initiate_workflow]), item: new_item, priority: workflow_priority) + new_item end