cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
PhilD
Level 8

Long patch operation occasionally only partially completes

My question is a fairly complex one but in real operation is causing unreliability and threatens the usefulness of my project.

 

Background

I have a series of apps, task entry, dispatch and iPhone app, that all work together to enter, assign and manage tasks all day in a hospital environment.

 

Tasks are entered on an app that has a form and tracking board, a central dispatcher has screens that have all the employees and their current status so they can be married to tasks. The employees are notified of a new task and acknowledge and ultimately complete their task, making them available again for new tasks. Tasks are cycled through in about 20 minutes on average so the apps skim off the top X number which works well. 

 

Main tables (SharePoint lists) include 'Employees', 'Tasks', 'Locations', etc. Many of my buttons involve patching both the Employees' & 'Tasks' list in one operation. For example to update a task's status to "Assigned" and an employee's status to "Active".

 

Problem

A long patch operation occasionally only partially completes when connectivity status changes.

 

My entire design works very well and is in current use, with thousands of tasks having been assigned and completed. One problem however is that if a data operation (such as the example operation shown below) is initiated on the iPhone app, and the device's connectivity changes (perhaps attempting to switch from cellular data to wifi), the operation can only partially complete, leaving the task's status and the employee's status out of sync. This is very intermittent and difficulty to produce occuring maybe five times out of a hundred. I can sometimes reproduce the problem by purposely turning off WiFi right after executing code like the example operation shown below in an environment with strong WiFi and cellular. A working theory is that the WiFi radio polling the device may be causing the device to switch when a weak network is detected, causing a switch to occur in the background, then causing the issue. Today we will be testing with devices set to only use cellular data as it is more reliable if the device were simply disconnected and the user could simply resume when they regained connectivity in a minute or two.

 

Question

Is there a design pattern I can incorporate some sort of protection against this happening?

 

I do not need offline capability. In fact I currently poll connectivity every so many seconds and have a shade that overlays the screen when not connected which works very well. Users simple wait to complete a task until they move to an area where the connectivity is good (and the shade goes away). 

 

Sorry for the long post but hoping to gain some insight from the experts in this community. Thanks!

 

Example operation

 

If(Connection.Connected, 

    Set(varShowWorkingShade,true);

    //SET TASK & EMPLOYEE VARIABLES***************************************************************************	
    Refresh(Tasks);
    Set(varTask,GalleryAllUsersTasks.Selected);
    Refresh(Employees);
    Set(varEmployee, varCurrentUserEmployeeTableRow); //employee table entry corresponding with logged in O365 user
    //END SET TASK & EMPLOYEE VARIABLES***************************************************************************

    ///SET EVENT STATUS MINUTES VARIABLES***************************************************************************
        //set the event class of the current event so we know which type to update later with the minutes in this status. choices are 'Employee' or 'Task' 

        Set(varCurrentEventClass,"Task"); // ** update to match current event class **
        Set(varPreviousEvent, Blank());
        
        //find last qualifying record by looking up the first one in a sorted, filtered set
        Refresh(Events);
        Set(varPreviousEvent,
            LookUp(Sort(Events,ID, Descending),               
                EventClass = varCurrentEventClass && TaskID = varTask.ID
            )
        );

    //END EVENT SET STATUS MINUTES VARIABLES***************************************************************************

    //WRITE PREVIOUS EVENT STATUS MINUTES ***************************************************************************
        //set the event's time to use in the calculation
        Set(varPreviousEventTime,varPreviousEvent.Time);
        
        // calculated minutes between previous time & now
        Set(varPreviousEventStatusMinutes,DateDiff(varPreviousEventTime,Now(),Minutes));

        //now write calculated number of minutes to previous event row determined earlier
        Patch(
        Events,
        LookUp(Events, ID = varPreviousEvent.ID),
        {StatusMinutes:varPreviousEventStatusMinutes}
        );

        // catch errors and record to a table
        If(!IsEmpty(Errors(Events).Record),  
            Patch(
            Errors,
            {ID: Blank()},  
            {Title: "Events table error"}, 
            {Error: First(Errors(Events)).Error}, 
            {Column: First(Errors(Events)).Column}, 
            {Message: First(Errors(Events)).Message}, 
            {Record: First(Errors(Events)).Record.ID}, 
            {ErrorDate:Now()},
            {App:varThisAppName}, 
            {Comments:"Writing event status minutes on Completed task self dispatch"}  // ** update this to indicate current context of error **
            );
            Revert(Events)
        );
    //END WRITE PREVIOUS EVENT STATUS MINUTES ***************************************************************************

    //WRITE NEW EVENT ***************************************************************************
        //write timestamped event for current update
            Patch(
            Events,
            {ID: Blank()}, 
                {Title: varThisAppName & " Event"},
                {EventClass:varCurrentEventClass}, // set earlier, no need to change
                {EventType:"Task Completed"}, // ** update this to indicate current context **
                {EmpID:varEmployee.EmpID}, //
                {TaskID:varTask.ID}, // 
                {TaskStatus:"Completed"},     // ** update to appropriate value for task
                {EmpStatus:"Available"},      // ** update to appropriate value for employee
                {Time:Now()}
            );
        
        // catch errors and record to a table
        If(!IsEmpty(Errors(Events)), 
            Patch(
            Errors, 
            {ID: Blank()}, 
            {Title: "Events Error"}, 
            {Error: First(Errors(Events)).Error}, 
            {Column: First(Errors(Events)).Column}, 
            {Message: First(Errors(Events)).Message}, 
            {Record: First(Errors(Events)).Record.ID}, 
            {ErrorDate:Now()}, 
            {App:varThisAppName}, 
            {Comments:"Completed Task self dispatch"} // ** update this to indicate current context **
            );
            Revert(Events) 
        );

    //END WRITE NEW EVENT ***************************************************************************

    //UPDATE CODE***************************************************************************

    //patch functions below are identical in both apps but the variables used are defined differently
        //update item
        Patch(
        Tasks,
        LookUp(Tasks, ID = varTask.ID),
        {TaskStatus: "Completed"}
        );
        
        //update item
        Patch(
        Employees,
        LookUp(Employees, ID = varEmployee.ID),
        {TaskAvailabilityStatus:"Available"},
        {LastLoc:varTask.DestLoc.Value},
        {LastStatusTime:Now()}
        );

    Concurrent(
        // catch errors and record to a table
        If(!IsEmpty(Errors(Tasks)), 
            Patch(
            Errors, 
            {ID: Blank()}, 
            {Title: "Tasks"},
            {Error: First(Errors(Tasks)).Error},
            {Column: First(Errors(Tasks)).Column},
            {Message: First(Errors(Tasks)).Message},
            {Record: First(Errors(Tasks)).Record.ID},
            {ErrorDate:Now()},
            {App:varThisAppName},
            {Comments:"Complete Task Self Dispatch"}
            );
            Revert(Tasks)
        ),
        
        // catch errors and record to a table
        If(!IsEmpty(Errors(Employees)), 
            Patch(
            Errors, 
            {ID: Blank()}, 
            {Title: "Employees"},
            {Error: First(Errors(Employees)).Error},
            {Column: First(Errors(Employees)).Column},
            {Message: First(Errors(Employees)).Message},
            {Record: First(Errors(Employees)).Record.ID},
            {ErrorDate:Now()},
            {App:varThisAppName},
            {Comments:"Complete Task Self Dispatch"}
            );
            Revert(Employees)
        )  
    );
    //END UPDATE CODE***************************************************************************   

    Set(varShowWorkingShade,false)
)

 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,918)