microsoft / powercat-automation-kit

Other
69 stars 18 forks source link

[Automation Kit - Feature]: Scheduler Proof of concept #383

Open Grant-Archibald-MS opened 9 months ago

Grant-Archibald-MS commented 9 months ago

Is your feature request related to a problem? Please describe.

The current process to schedule and manage Power Automate Desktop (PAD) execution is limited, which makes it difficult to automate certain tasks. For example, it's not easy to schedule PAD executions based on specific criteria or to manage multiple schedules in a centralized way.

Propose to develop a Scheduler Proof of Concept (PoC) that would allow users to schedule PAD executions in a more flexible and powerful way. The Scheduler PoC would leverage the existing PAD APIs for starting executions and the Power Automate platform for running flows on a schedule.

Describe the solution you'd like

Describe alternatives you've considered

No response

Additional context?

Consider the following options:

  1. Queue items as Work Queue items
  2. On expiry of work queue item trigger the PAD via API
  3. Methods to add new items to the work queue based on defined schedule
  4. Providing the ability to change the queue time for a specific execution of a schedule
  5. The ability to define dependencies between queue items

AB#1466

Grant-Archibald-MS commented 9 months ago

Consider the following approaches to trigger the Power Automate Desktop:

Triggering Power Automate Desktop

  1. Manual testing - Get the access token
  2. Call the dataverse unbound action from a Datavesrse unbound actions

Power Automate Cloud Flow Trigger Patterns to evaluate

Power Automate Cloud Flow Delay Until

  1. Create Dataverse custom schedule table with Next Run Date Time
  2. Dataverse Trigger on Update of custom schedule table
  3. Use the Delay Until the date https://learn.microsoft.com/en-us/power-automate/dataverse/wait-conditions
  4. After the Delay Until trigger desktop flow
  5. Update CalculateNext to True
  6. Add Dataverse Plugin to recalculate next Run when CalculateNext = True using https://www.nuget.org/packages/ncrontab/ to calculate the next run time

[!NOTE] Will need to consider approach when the Delay until needs to stopped or rescheduled to a new time

Power Automate Cloud flow

  1. Use a timer trigger that runs every 5 mins
  2. Evaluate records in Work Queue Item use delayuntil or expirydate
  3. For each record ready to run execute the unbound action to trigger flow
  4. Add new item to work queue to represent the next run time
Grant-Archibald-MS commented 9 months ago
Approach Pros Cons
Power Automate Cloud Flow Delay Until Could have multiple cloud flows that listen to Dataverse table If need to reschedule then need to cancel the scheduled flow and start a new one
Do not need to poll the table for changes How schedule multiple next runs?
Use Chat GPT to use natural language to generate the cron expression
Power Automate Cloud flow Timer Can schedule multiple items as each item is a work queue item row Only run on time window of recurring time schedule
Can update the delay until or expiry date with simple Dataverse PATCH Single point of failure

For the delay until will need:

Grant-Archibald-MS commented 9 months ago

User Experience. End state:

  1. Select a Month, Week, Day

  2. Simple case See a list of times that records in Desktop Flow Schedule that will run based on the crontab values. For example

    Desktop Flow Schedule Next Run Cron Expression
    Test Flow 0 10 1-5 2023-12-11 10:00AM Run at 10:00 AM every weekday

    Display

    Select week of 11th Dec 2023

    Mon 11 10:00AM Tue 12 10:00AM Wed 13 10:00AM Thu 14 10:00AM Friday 15 10:00AM

  3. Extended case

    Desktop Flow Schedule Next Run Cron Expression Priority Start Date End Date
    Test Flow 0 10 1-5 2023-12-11 10:00AM Run at 10:00 AM every weekday 1
    Test Flow (Wed) 0 11 3 Run at 10:00 AM every weekday 2 12-13-2023 12-13-2023

    Display

    Select week of 11th Dec 2023

    Mon 11 10:00AM (Test Flow 1) Tue 12 10:00AM (Test Flow 1) Wed 13 11:00AM (Test Flow 2) Thu 14 10:00AM (Test Flow 1) Friday 15 10:00AM (Test Flow 1)

Grant-Archibald-MS commented 8 months ago

@praveen-pulagam-gl consider the following enhancements

User Experience

Dataverse Changes

Column Type Description
Name Text Name of the schedule
Automation Schedule GUID Identifier of schedule
Type ?? Desktop Flow or Dataverse
Next Run Date Time
Run Now Boolean
Column Type Description
Automation Schedule GUID Identifier of parent
Automation Type Enumerated Type Desktop Flow or Dataverse
Cron Expression Text
Cron Expression Description Text
Start Date Date Time
End Date Date Time
Priority Int

Cloud Flow Changes