summaryrefslogtreecommitdiff
path: root/1 Projects/Resumable tasks goba/Prototype resumable task.md
diff options
context:
space:
mode:
authorJasper Ras <jras@hostnet.nl>2025-03-20 11:07:49 +0100
committerJasper Ras <jras@hostnet.nl>2025-03-20 11:07:49 +0100
commit80ccf68f55dbb70d7e5ed52ee95b3c9d1b6ce264 (patch)
tree93e28e85ab70052aa6f577998ec7dc1f413b40c0 /1 Projects/Resumable tasks goba/Prototype resumable task.md
parent9642cd7ae24f0ba79ce5647c709b35ae8f06a285 (diff)
vault backup: 2025-03-20 11:07:48
Diffstat (limited to '1 Projects/Resumable tasks goba/Prototype resumable task.md')
-rw-r--r--1 Projects/Resumable tasks goba/Prototype resumable task.md62
1 files changed, 0 insertions, 62 deletions
diff --git a/1 Projects/Resumable tasks goba/Prototype resumable task.md b/1 Projects/Resumable tasks goba/Prototype resumable task.md
deleted file mode 100644
index fb58a4e..0000000
--- a/1 Projects/Resumable tasks goba/Prototype resumable task.md
+++ /dev/null
@@ -1,62 +0,0 @@
----
-tags:
- - taskflow
- - "#openstack"
----
-```python
-import time
-import contextlib
-
-from taskflow.patterns import linear_flow as lf
-from taskflow import task, engines
-from taskflow.persistence import backends, models
-from taskflow.exceptions import NotFound
-
-
-class PrintAndWait(task.Task):
- def execute(self, *args, **kwargs):
- print(self.name)
- time.sleep(10)
- return self.name
-
-
-def logbook_and_flow_detail(backend, id):
- conn = backend.get_connection()
-
- try:
- logbook = conn.get_logbook(id)
- flow_detail = logbook.find(id)
- except NotFound:
- logbook = models.LogBook("printer_log", uuid=id)
- flow_detail = models.FlowDetail("cool flow", uuid=id)
- logbook.add(flow_detail)
-
- with contextlib.closing(backend.get_connection()) as conn:
- conn.upgrade()
- conn.save_logbook(logbook)
-
- return logbook, flow_detail
-
-
-def create_flow():
- main_flow = lf.Flow("main_flow")
-
- for i in range(10):
- main_flow.add(PrintAndWait(name=f"print_n_wait_{i}"))
-
- return main_flow
-
-
-def main():
- backend = backends.fetch(conf=dict(connection="sqlite:///test.db"))
- logbook, flow_detail = logbook_and_flow_detail(backend, "1")
-
- flow = create_flow()
- eng = engines.load(flow, flow_detail=flow_detail, backend=backend, book=logbook)
-
- eng.run()
-
-
-if __name__ == "__main__":
- main()
-``` \ No newline at end of file