Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nick Frederiksen 18 posts 77 karma points
    Apr 04, 2016 @ 09:23
    Nick Frederiksen
    0

    Get current Workflow from WorkflowType.Execute-method

    Hi,

    I am doing some data collection using umbraco forms and sending the collected data to a 3rd party using a custom workflow type, executed on submit.

    The 3rd party service, can however not be trusted to have the same uptime / reliability as the Umbraco site on which the data is collected.

    I have therefore begun implementing a retry routine which should be able to re-execute failed workflows.

    This work has now come across an obstacle:

    I am not able to identify the executing workflow from my workflow type

    On the workflow type, there is a property called Workflow. However, this property is null, unless the LoadSettings method is called. This method, takes a workflow, which i cannot get.

    The reason I need the workflow, is that I need the settings and a form could have multiple workflows of the same type with different settings, where one could execute without errors and the other could fail. I need to only execute the one that failed.

    I am using Umbraco 7.2.8 and Umbraco Forms 4.1.4

    My code so far, non essentials removed:

    public class ThirdPartySenderWorkFlowType : WorkflowType
    {
        public static Guid ID = new Guid("eead7e12-89c5-4d77-956e-ae27ce15d178");
    
        public ThirdPartySenderWorkFlowType()
        {
            this.Name = "Send data + PDF to 3rd party";
            this.Id = ID;
            this.Description = "Sending data to 3rd party";
        }
    
        public override Umbraco.Forms.Core.Enums.WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
        {
            // ... Fetch data collection settings.
    
            // ... Generate PDF
    
            if (hasFile)
            {
                // ... Send PDF
                if (!ufr.IsSuccess) // ... if PDF send failed
                {
                    repo.RegisterFailedCompletionAttempt(flow, Workflow.Id, save: false);
                    return Umbraco.Forms.Core.Enums.WorkflowExecutionStatus.Failed;
                }
            }
    
            // ... Create data document
    
            // ... Save data document data to local DB.
    
            if (createDocumentResult.IsSuccess)
            {
                repo.CompleteFlow(flow, Workflow.Id, save: false);
            }
            else
            {
                repo.RegisterFailedCompletionAttempt(flow, Workflow.Id, save: false);
            }
    
            return Umbraco.Forms.Core.Enums.WorkflowExecutionStatus.Completed;
        }
    
        public override List<Exception> ValidateSettings()
        {
            var errors = new List<Exception>();
            return errors;
        }
    }
    
  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Apr 04, 2016 @ 09:40
    Warren Buckley
    0

    Hello Nick,
    I am just trying to fully understand the problem here.

    You are trying to get the Workflow that is currently being executed (inside your custom workflow) to store in some retry DB table?

    If that is the case then surely you know the workflow type as it will be the currently one you are writing your code in.

    Sorry if I totally mis understanding your question you are asking here, it's Monday :)

    Thanks,
    Warren

  • Nick Frederiksen 18 posts 77 karma points
    Apr 04, 2016 @ 09:53
    Nick Frederiksen
    0

    Hi,

    I am trying to identify the workflow. I do know the type, since this is the one I have implemented...

    But I need to know the workflow.

    A form could have three workflows, but only two workflow types:

    • Workflow A, type 1
    • Workflow B, type 1
    • Workflow C, type 2

    Lets say I have implemented type 1. Workflow A and B are both of that type. If I tried to identify the workflow using the type:

    workflowStorage.GetAllWorkFlows(form).Where(w => w.WorkflowTypeId == new Guid(""));
    

    This would get me both workflow A + B. Which would be great if i had to retry both, but if I only had to retry one of them, which would that be?

    What I need is for my workflow type, (type 1), to know whether Workflow A or B is the one being executed.

  • Savan Rojasara 1 post 21 karma points
    Jun 08, 2022 @ 10:21
    Savan Rojasara
    0

    Hi Nick I want to add GetAllWorkFlow method in umbraco 9 like from WorkflowStorage we are getting in u8.

    so how can we get it done in umbraco 9.

    here, is the example in umbraco 8 previously we did

    WorkflowStorage workflowStorage = new WorkflowStorage(); FormStorage formStorage = new FormStorage();

                var flowData = workflowStorage.GetAllWorkFlows().Where(w => w.WorkflowTypeId == new Guid(calculatWorkFlow.Id.ToByteArray()) && w.Form.ToString() == formId).FirstOrDefault(); &&
    
                        var form = formStorage.GetAllForms().Where(x => x.Id == new Guid(flowData.Form.ToByteArray())).SingleOrDefault().AllFields.Where(p => source.Any(p2 => new Guid(p2.Value) == p.Id)).ToList();
    

    Thanks.

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Apr 04, 2016 @ 10:10
    Warren Buckley
    0

    Hi Nick,
    Each workflow item is persisted to JSON on disk so this will give you a better understanding and can be found /App_Plugins/UmbracoForms/Data/Workflows

    Each Workflow item that gets created for a form has an ID/GUID so I would use that ID to log which Workflow item that failed.

    So your LINQ could look for all workflow types with the GUID of your custom workflow type and for any that fail then log/store the ID of the workflow item that failed to execute for retying later on.

    I hope this helps you.
    Warren

  • Nick Frederiksen 18 posts 77 karma points
    Apr 04, 2016 @ 11:00
    Nick Frederiksen
    0

    Hi,

    So your suggestion is to subscribe to the "WorkflowService.WorkflowFailed"-event?

    This would work, if I had a way to get the record from that event.

    The situation thus far:

    A workflow type, knows about its settings and recorded data. But not its workflow.

    The WorkflowFailed-event, knows about the failed workflow, but has no idea about recorded data.

    I cannot retry a workflow without record data, and I cannot reliably run a workflow type without knowing the workflow, from which to get the correct settings.

    I cannot even log the workflow as "failed" from the event, since I have no idea in which context that workflow has failed.

    The workflow could fail for one record, but be successful on an other. Without the distinction, I would end up either retrying successful workflows, or no workflows at all.

    From my point of view, there seems to be a bug in Forms, where the Workflow property is not being set properly when being executed.

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Apr 04, 2016 @ 13:24
    Warren Buckley
    0

    Hi Nick,
    It does seems a bit of a bug. Would you mind logging this on the issue tracker with details & steps to replicate so when I get a chance to look at this most likely next sprint that I won't forget the details.

    issues.umbraco.org/issues/CON

    Thanks,
    Warren

  • Nick Frederiksen 18 posts 77 karma points
    Apr 04, 2016 @ 13:39
    Nick Frederiksen
    0

    Done:

    http://issues.umbraco.org/issue/CON-959

    Thanks in advance...

Please Sign in or register to post replies

Write your reply to:

Draft