Domanda

I'm primarily a c# developer and looking for some guidance (theory and/or code samples) on designing a finite state machine for a series of long running processes. Each operation defined can run for several minutes. I'm simply using the Windows Task Scheduler to manage scheduling and instancing.

Below is a simplified outline of what I'm looking at. So far, I've built the Op Status FSM using Stateless. Now, I'm trying to figure out the best way to handle the sequencing of the operations with some conditions thrown in, such as item #3 shows. These conditions are based on data resulting from Op2.

Options I've consider so far:

  • Create a FSM for the operation sequence (seems overly complex, but maybe I'm missing a fundamental somewhere)
  • Create an operation manager for each operation and let each manager worry about what state(s) it's interested in along with what the next state should be

OPERATIONS -> NEXT OPERATION IN SEQUENCE

  1. None -> Op1
  2. Op1 -> Op2
  3. Op2 -> Op3 or Op4 conditionally
  4. Op3 -> Op4
  5. Op4 -> Op5
  6. Op5 -> None

OP STATUS

  • Idle
    • Trigger: Scheduled -> Pending
    • Constraint: Operation must be set
  • Pending
    • Trigger: Run -> Running
  • Running
    • Trigger: Failed -> Error
    • Trigger: Success -> Idle
    • Trigger: NotReady -> Pending
  • Error
    • Trigger: Retry -> Pending
    • Trigger: Cancel -> Idle (remove assigned operation)
È stato utile?

Soluzione

This really sounds like the specific use case intended for Windows Workflow Foundation. It provides all of the required plumbing to handle this type of scenario, including the ability to persist the workflows, restart them, etc.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top