diff --git a/bin/get_bpmn_json_for_process_instance b/bin/get_bpmn_json_for_process_instance new file mode 100755 index 00000000..0ddbfe2b --- /dev/null +++ b/bin/get_bpmn_json_for_process_instance @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import os +import sys + +from spiffworkflow_backend import create_app +from spiffworkflow_backend.models.process_instance import ProcessInstanceModel + + +def main(process_instance_id: str): + os.environ["FLASK_ENV"] = "development" + flask_env_key = "FLASK_SESSION_SECRET_KEY" + os.environ[flask_env_key] = "whatevs" + app = create_app() + with app.app_context(): + process_instance = ProcessInstanceModel.query.filter_by(id=process_instance_id).first() + + if not process_instance: + raise Exception(f"Could not find a process instance with id: {process_instance_id}") + + with open(f'/tmp/{process_instance_id}_bpmn_json.json', 'w', encoding="utf-8") as f: + f.write(process_instance.bpmn_json) + + +if len(sys.argv) < 2: + raise Exception("Process instance id not supplied") + +main(sys.argv[1])