Workflow
Workflow Manager Documentation
Overview
user_code:User Code: com.finmars.standard-workflow:workflow-manager
payload:
optionalPayload: Optional
ВоркфлоуThe менеджерWorkflow предназначенManager дляis запускаdesigned воркеровto вexecute требуемоемworkers порядкеin сa определеннымspecific order with a defined payload. Its primary use case is when no payload is provided.
Основной
Workflow сценарийManager использования воркфлоу менеджера предназачен при отсутствии payload.
Сценарий его работы:
ПрочитатьReadилиorсоздатьcreateфайлthe/states/
fileglobal\_state\_manager.global_state_manager.jsonПрочитатьReadвсеalljsonJSONменеджеровmanagerвfiles in/states/managers
ПрочитатьReadстатусtheвыполненияexecutionкаждогоstatusменеджераofизeachполяmanager from the "status"вfieldсоотетствующемinjsonthe corresponding JSONРаспределитьCategorizeстейтstateфайлыfilesпоbyстатусамstatusвinвидеaсловаряdictionary format:
{
"to-do": [],
"in-progress": [
"com.finmars.standard-workflow:workflow-manager-20240821095322.json"
],
"done": [
"com.finmars.standard-workflow:workflow-manager-20240724101635.json",
"com.finmars.standard-workflow:workflow-manager-20240724104102.json"
],
"paused": []
}
ЗапуститьExecuteлогикуtheобработкиlogicданныхforстейт-файловЛогикаprocessingобработкиtheseglobal_state_manager.jsonstate files
Global State Manager Processing Logic
ПопытатьсяAttemptпрочитатьtoфайлread theglobal_state_manager.json
.Еслиfile.нет,Ifтоitсоздатьdoesn'tего.exist, create it.ПрочитатьReadсписокtheфайловlistизof files from/states/managers/
.РаспределитьCategorizeпоbyстатусамstatusиandсохранитьsaveвinglobal_state_manager.json
:ЕслиIfфайлаtheнет,fileтоdoesn'tдобавитьexist,вaddto_doit to "to-do"ЕслиIfвit's in "to-do,do",тоchangeсменитьtheстатусstatusнаto "in-progressprogress"ЕслиIfфайлtheесть,fileтоexists,обновитьupdateстатусits status
ПрочитатьReadсодержимоеtheфайлаcontentsизofthe file in "in-
progress"progressЛогика обработки загруженного стейта файла менеджераstatus
Interaction
with global_state_manager.json
with global_state_manager.json
The global_state_manager.json
file serves as a central registry for all workflow states in the system:
-
Initialization: If
global_state_manager.json
doesn't exist, it's created by scanning the/states/managers/
directory and categorizing all existing state manager files. -
Retrieval: The existing
global_state_manager.json
is loaded and its data is updated. -
Updating: The global state manager is updated by:
- Identifying and adding new state manager files to the "in-progress" category
- Checking and updating the status of each tracked state manager file
- Moving state managers between categories based on their current status
-
Saving: After updates, the modified
global_state_manager.json
is saved back to storage. -
Workflow Processing: The main
workflow_manager
function uses data fromglobal_state_manager.json
to determine which state managers to process when no specific payload is provided.
State Managers and Workers/Items Interaction
Each state manager file represents an individual workflow instance, containing information about its workers and their respective items (tasks):
-
Loading: Individual state manager files are loaded based on paths stored in
global_state_manager.json
or provided in the payload. -
Status Propagation: Each worker's status is updated based on the statuses of its items.
-
Worker Processing: For each worker in a state manager:
- Skipped if status is 'success', 'skip', or 'ignore'
- If 'in-progress', each item's status is checked:
- 'in-progress' items: latest state is fetched and updated
- 'to-do' items: a new workflow is initiated
- If 'to-do', processing starts with the first 'to-do' item
-
Item State Management: Each item within a worker has its own state, including a
state_path
used to fetch and update item-specific states. -
Workflow Initiation: New items are processed by calling the
start_workflow
function with the appropriate user code and payload. -
State Updating: After any changes, the modified state manager is saved back to its file.