design patterns - Workflow System with Azure Table Storage -
i have system need run simple workflow. example:
- on jan 1st 08:15 trigger task object z
- when triggered run code (implementation details not important)
- schedule task b object z run @ jan 3rd 10:25 (and on)
the workflow simple, need run 500.000+ instances , that's tricky part.
i know windows workflow foundation , same reason have chosen not use that.
my initial design use azure table storage , appreciate feedback on design.
the system consist of 2 tables
table "jobs" partitionkey: objectid rowkey: processon (utc ticks in reverse newest on top) attributes: state (pending, processed, error, skipped), etc... table "timetable" partitionkey: yyyymmdd rowkey: yyyymmddhhmm_<guid> attributes: job_partitionkey, job_rowkey
the idea runs table have complete history of jobs per object , timetable have list of jobs run in future.
some assumptions:
- a job never span more 1 object
- there ever 1 pending job per object
- the "job" lightweight e.g. posting message queue
the system must able perform these tasks:
execute pending jobs
- query records in "timetable" "partition <= today" , "rowkey <= today"
- for each record (in parallel)
- lookup job in jobs table via partitionkey , rowkey
- if "not exists" or state != pending skip
- execute "logic". if fails => log , maybe retry logic
- submit "next run date in timetable"
- submit "update state = processed" , "new job record (next run)" single transaction
- when finished => delete processed timetable records
concern: 2 of 3 records modifications in transaction. overcome in way?
stop workflow stop/pause workflow object z
- query top 1 jobs in jobs table partitionkey
- if , state == pending update "cancelled"
- (no need bother cleaning timetable clean "when time comes")
start workflow
- create pending record in jobs table
- create record in timetable
in terms of "executing thing" using azure function or scheduler-thing execute pending jobs every 5 minutes or so.
any comments or suggestions highly appreciated.
thanks!
how using service bus instead? brokeredmessage class has property called scheduledenqueuetimeutc. can schedule when want jobs run via scheduledenqueuetimeutc property, , fuggedabouddit. can have triggered webjob monitors service bus messaging queue, , triggered near when job message enqueued. i'm big fan of relying on existing services minimize coding needed.
Comments
Post a Comment