Merge branch 'main' of github.com:sartography/spiff-arena
This commit is contained in:
commit
612d63f141
|
@ -1,16 +1,22 @@
|
|||
#!/usr/bin/env python
|
||||
# ^ for syntax highlighting
|
||||
"""Get the bpmn process json for a given process instance id and store it in /tmp."""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
from spiffworkflow_backend import create_app
|
||||
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
||||
from spiffworkflow_backend.services.process_instance_processor import (
|
||||
ProcessInstanceProcessor,
|
||||
)
|
||||
|
||||
|
||||
def main(process_instance_id: str):
|
||||
def main(process_instance_id: str) -> None:
|
||||
"""Main."""
|
||||
os.environ["SPIFFWORKFLOW_BACKEND_ENV"] = "local_development"
|
||||
if os.environ.get("SPIFFWORKFLOW_BACKEND_BPMN_SPEC_ABSOLUTE_DIR") is None:
|
||||
os.environ["SPIFFWORKFLOW_BACKEND_BPMN_SPEC_ABSOLUTE_DIR"] = "hey"
|
||||
os.environ["SPIFFWORKFLOW_BACKEND_BPMN_SPEC_ABSOLUTE_DIR"] = "hey"
|
||||
flask_env_key = "FLASK_SESSION_SECRET_KEY"
|
||||
os.environ[flask_env_key] = "whatevs"
|
||||
app = create_app()
|
||||
|
@ -19,16 +25,18 @@ def main(process_instance_id: str):
|
|||
id=process_instance_id
|
||||
).first()
|
||||
|
||||
file_path = f"/tmp/{process_instance_id}_bpmn_json.json"
|
||||
file_path = f"/var/tmp/{process_instance_id}_bpmn_json.json"
|
||||
if not process_instance:
|
||||
raise Exception(
|
||||
f"Could not find a process instance with id: {process_instance_id}"
|
||||
)
|
||||
|
||||
with open(
|
||||
file_path, "w", encoding="utf-8"
|
||||
) as f:
|
||||
f.write(process_instance.bpmn_json)
|
||||
with open(file_path, "w", encoding="utf-8") as f:
|
||||
f.write(
|
||||
json.dumps(
|
||||
ProcessInstanceProcessor._get_full_bpmn_json(process_instance)
|
||||
)
|
||||
)
|
||||
print(f"Saved to {file_path}")
|
||||
|
||||
|
||||
|
|
|
@ -86,7 +86,6 @@ def process_list() -> Any:
|
|||
def _process_data_fetcher(
|
||||
process_instance_id: int,
|
||||
process_data_identifier: str,
|
||||
modified_process_model_identifier: str,
|
||||
download_file_data: bool,
|
||||
index: Optional[int] = None,
|
||||
) -> flask.wrappers.Response:
|
||||
|
@ -140,9 +139,8 @@ def process_data_show(
|
|||
return _process_data_fetcher(
|
||||
process_instance_id,
|
||||
process_data_identifier,
|
||||
modified_process_model_identifier,
|
||||
False,
|
||||
None,
|
||||
download_file_data=False,
|
||||
index=None,
|
||||
)
|
||||
|
||||
|
||||
|
@ -156,9 +154,8 @@ def process_data_file_download(
|
|||
return _process_data_fetcher(
|
||||
process_instance_id,
|
||||
process_data_identifier,
|
||||
modified_process_model_identifier,
|
||||
True,
|
||||
index,
|
||||
download_file_data=True,
|
||||
index=index,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -167,8 +167,7 @@ def process_instance_suspend(
|
|||
) -> flask.wrappers.Response:
|
||||
"""Process_instance_suspend."""
|
||||
process_instance = _find_process_instance_by_id_or_raise(process_instance_id)
|
||||
processor = ProcessInstanceProcessor(process_instance)
|
||||
processor.suspend()
|
||||
ProcessInstanceProcessor.suspend(process_instance)
|
||||
return Response(json.dumps({"ok": True}), status=200, mimetype="application/json")
|
||||
|
||||
|
||||
|
@ -178,8 +177,7 @@ def process_instance_resume(
|
|||
) -> flask.wrappers.Response:
|
||||
"""Process_instance_resume."""
|
||||
process_instance = _find_process_instance_by_id_or_raise(process_instance_id)
|
||||
processor = ProcessInstanceProcessor(process_instance)
|
||||
processor.resume()
|
||||
ProcessInstanceProcessor.resume(process_instance)
|
||||
return Response(json.dumps({"ok": True}), status=200, mimetype="application/json")
|
||||
|
||||
|
||||
|
|
|
@ -254,7 +254,10 @@ def task_show(process_instance_id: int, task_id: str) -> flask.wrappers.Response
|
|||
|
||||
form_schema_file_name = ""
|
||||
form_ui_schema_file_name = ""
|
||||
spiff_task = _get_spiff_task_from_process_instance(task_id, process_instance)
|
||||
processor = ProcessInstanceProcessor(process_instance)
|
||||
spiff_task = _get_spiff_task_from_process_instance(
|
||||
task_id, process_instance, processor=processor
|
||||
)
|
||||
extensions = spiff_task.task_spec.extensions
|
||||
|
||||
if "properties" in extensions:
|
||||
|
@ -263,7 +266,6 @@ def task_show(process_instance_id: int, task_id: str) -> flask.wrappers.Response
|
|||
form_schema_file_name = properties["formJsonSchemaFilename"]
|
||||
if "formUiSchemaFilename" in properties:
|
||||
form_ui_schema_file_name = properties["formUiSchemaFilename"]
|
||||
processor = ProcessInstanceProcessor(process_instance)
|
||||
task = ProcessInstanceService.spiff_task_to_api_task(processor, spiff_task)
|
||||
task.data = spiff_task.data
|
||||
task.process_model_display_name = process_model.display_name
|
||||
|
@ -612,7 +614,7 @@ def _render_jinja_template(unprocessed_template: str, spiff_task: SpiffTask) ->
|
|||
)
|
||||
raise wfe from template_error
|
||||
except Exception as error:
|
||||
type, value, tb = exc_info()
|
||||
_type, _value, tb = exc_info()
|
||||
wfe = WorkflowTaskException(str(error), task=spiff_task, exception=error)
|
||||
while tb:
|
||||
if tb.tb_frame.f_code.co_filename == "<template>":
|
||||
|
|
|
@ -1090,7 +1090,7 @@ class ProcessInstanceProcessor:
|
|||
self.add_step()
|
||||
self.save()
|
||||
# Saving the workflow seems to reset the status
|
||||
self.suspend()
|
||||
self.suspend(self.process_instance_model)
|
||||
|
||||
def reset_process(self, spiff_step: int) -> None:
|
||||
"""Reset a process to an earlier state."""
|
||||
|
@ -1134,7 +1134,7 @@ class ProcessInstanceProcessor:
|
|||
db.session.delete(row)
|
||||
|
||||
self.save()
|
||||
self.suspend()
|
||||
self.suspend(self.process_instance_model)
|
||||
|
||||
@staticmethod
|
||||
def get_parser() -> MyCustomParser:
|
||||
|
@ -1857,14 +1857,16 @@ class ProcessInstanceProcessor:
|
|||
db.session.add(self.process_instance_model)
|
||||
db.session.commit()
|
||||
|
||||
def suspend(self) -> None:
|
||||
@classmethod
|
||||
def suspend(cls, process_instance: ProcessInstanceModel) -> None:
|
||||
"""Suspend."""
|
||||
self.process_instance_model.status = ProcessInstanceStatus.suspended.value
|
||||
db.session.add(self.process_instance_model)
|
||||
process_instance.status = ProcessInstanceStatus.suspended.value
|
||||
db.session.add(process_instance)
|
||||
db.session.commit()
|
||||
|
||||
def resume(self) -> None:
|
||||
@classmethod
|
||||
def resume(cls, process_instance: ProcessInstanceModel) -> None:
|
||||
"""Resume."""
|
||||
self.process_instance_model.status = ProcessInstanceStatus.waiting.value
|
||||
db.session.add(self.process_instance_model)
|
||||
process_instance.status = ProcessInstanceStatus.waiting.value
|
||||
db.session.add(process_instance)
|
||||
db.session.commit()
|
||||
|
|
|
@ -1511,7 +1511,7 @@ class TestProcessApi(BaseTest):
|
|||
)
|
||||
processor.save()
|
||||
|
||||
processor.suspend()
|
||||
processor.suspend(process_instance)
|
||||
payload["description"] = "Message To Suspended"
|
||||
response = client.post(
|
||||
f"/v1.0/messages/{message_model_identifier}",
|
||||
|
@ -1525,7 +1525,7 @@ class TestProcessApi(BaseTest):
|
|||
assert response.json
|
||||
assert response.json["error_code"] == "message_not_accepted"
|
||||
|
||||
processor.resume()
|
||||
processor.resume(process_instance)
|
||||
payload["description"] = "Message To Resumed"
|
||||
response = client.post(
|
||||
f"/v1.0/messages/{message_model_identifier}",
|
||||
|
|
Loading…
Reference in New Issue