@colabo-flow/s-go 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/DEVELOPMENT.md +38 -0
  2. package/README.md +110 -0
  3. package/__init__.py +0 -0
  4. package/__pycache__/__init__.cpython-39.pyc +0 -0
  5. package/create_client.py +84 -0
  6. package/create_host.py +91 -0
  7. package/create_host_terra.py +103 -0
  8. package/demo/__init__.py +0 -0
  9. package/demo/create-client.ts +51 -0
  10. package/demo/create-host.ts +136 -0
  11. package/demo/send-simple-recommended.py +26 -0
  12. package/demo/send-simple.py +50 -0
  13. package/demo/send.py +352 -0
  14. package/demo/send.ts +40 -0
  15. package/demo/threading/README.md +14 -0
  16. package/demo/threading/basic_consumer_connection_threaded.png +0 -0
  17. package/demo/threading/basic_consumer_connection_threaded.py +135 -0
  18. package/demo/threading/basic_consumer_threaded.py +100 -0
  19. package/demo/threading/long-running-publisher.py +68 -0
  20. package/docs/ColaboFlow-infrastructure-diagram.png +0 -0
  21. package/docs/workflow.md +35 -0
  22. package/index.ts +4 -0
  23. package/jest.config.ts +172 -0
  24. package/lib/__init__.py +0 -0
  25. package/lib/__pycache__/__init__.cpython-39.pyc +0 -0
  26. package/lib/__pycache__/config.cpython-39.pyc +0 -0
  27. package/lib/__pycache__/executor_operators.cpython-39.pyc +0 -0
  28. package/lib/__pycache__/executor_vos.cpython-39.pyc +0 -0
  29. package/lib/__pycache__/go_amqp_client.cpython-39.pyc +0 -0
  30. package/lib/__pycache__/go_amqp_client_threaded.cpython-39.pyc +0 -0
  31. package/lib/__pycache__/go_amqp_host.cpython-39.pyc +0 -0
  32. package/lib/__pycache__/operators.cpython-39.pyc +0 -0
  33. package/lib/__pycache__/vos.cpython-39.pyc +0 -0
  34. package/lib/config.py +21 -0
  35. package/lib/config.ts +22 -0
  36. package/lib/executor_operators.py +23 -0
  37. package/lib/executor_vos.py +318 -0
  38. package/lib/go.amqp.client-old-basic.py +50 -0
  39. package/lib/go.amqp.client.ts +100 -0
  40. package/lib/go.amqp.host-old-basic.py +48 -0
  41. package/lib/go.amqp.host.ts +269 -0
  42. package/lib/go.amqp.host_status.ts +81 -0
  43. package/lib/go.amqp.service.ts +272 -0
  44. package/lib/go_amqp_client.py +263 -0
  45. package/lib/go_amqp_client_non_threaded.py +152 -0
  46. package/lib/go_amqp_host.py +348 -0
  47. package/lib/operators.py +16 -0
  48. package/lib/operators.ts +17 -0
  49. package/lib/params.ts +1 -0
  50. package/lib/vos.py +232 -0
  51. package/lib/vos.ts +212 -0
  52. package/package.json +36 -0
  53. package/requirements.txt +4 -0
  54. package/tests/units/README.md +12 -0
  55. package/tests/units/chalk/index.ts +41 -0
  56. package/tests/units/go.amqp.host.test.ts +116 -0
  57. package/tests/units/tests-vos/tasks-and-flows.vos.ts +128 -0
  58. package/tsconfig.json +45 -0
  59. package/v1 - GRPC/README.md +18 -0
  60. package/v1 - GRPC/node/README.md +13 -0
  61. package/v1 - GRPC/node/colaboflow_go_actionhost_client.ts +91 -0
  62. package/v1 - GRPC/node/colaboflow_go_actionhost_server.ts +84 -0
  63. package/v1 - GRPC/node/colaboflow_go_client.ts +82 -0
  64. package/v1 - GRPC/node/colaboflow_go_server.ts +84 -0
  65. package/v1 - GRPC/node/demos/demo-colaboflow_go_actionhost_client.ts +21 -0
  66. package/v1 - GRPC/node/index.ts +3 -0
  67. package/v1 - GRPC/node/package-lock.json +770 -0
  68. package/v1 - GRPC/node/package.json +30 -0
  69. package/v1 - GRPC/node/tsconfig.json +32 -0
  70. package/v1 - GRPC/node/yarn.lock +642 -0
  71. package/v1 - GRPC/protos/colabo/flow/go/go.proto +135 -0
  72. package/v1 - GRPC/python/DEVELOPMENT.md +86 -0
  73. package/v1 - GRPC/python/DISCUSSION.md +8 -0
  74. package/v1 - GRPC/python/LICENSE.txt +21 -0
  75. package/v1 - GRPC/python/README.md +45 -0
  76. package/v1 - GRPC/python/__init__.py +1 -0
  77. package/v1 - GRPC/python/colabo/__init__.py +3 -0
  78. package/v1 - GRPC/python/colabo/flow/__init__.py +3 -0
  79. package/v1 - GRPC/python/colabo/flow/go/__init__.py +12 -0
  80. package/v1 - GRPC/python/colabo/flow/go/basic/PuzzleImporter.py +77 -0
  81. package/v1 - GRPC/python/colabo/flow/go/basic/__init__.py +5 -0
  82. package/v1 - GRPC/python/colabo/flow/go/basic/colaboflow_go_basic.py +66 -0
  83. package/v1 - GRPC/python/colabo/flow/go/basic/parseFlowJSON.py +32 -0
  84. package/v1 - GRPC/python/colabo/flow/go/colaboflow_go_actionhost.py +44 -0
  85. package/v1 - GRPC/python/colabo/flow/go/colaboflow_go_client.py +48 -0
  86. package/v1 - GRPC/python/colabo/flow/go/colaboflow_go_demo.py +168 -0
  87. package/v1 - GRPC/python/colabo/flow/go/go_pb2.py +976 -0
  88. package/v1 - GRPC/python/colabo/flow/go/go_pb2_grpc.py +139 -0
  89. package/v1 - GRPC/python/colabo.flow.go.egg-info/PKG-INFO +58 -0
  90. package/v1 - GRPC/python/colabo.flow.go.egg-info/SOURCES.txt +16 -0
  91. package/v1 - GRPC/python/colabo.flow.go.egg-info/dependency_links.txt +1 -0
  92. package/v1 - GRPC/python/colabo.flow.go.egg-info/requires.txt +3 -0
  93. package/v1 - GRPC/python/colabo.flow.go.egg-info/top_level.txt +2 -0
  94. package/v1 - GRPC/python/demo-0.py +69 -0
  95. package/v1 - GRPC/python/demo-1.py +146 -0
  96. package/v1 - GRPC/python/demo-actionhost.py +47 -0
  97. package/v1 - GRPC/python/demo-basic.md +13 -0
  98. package/v1 - GRPC/python/demo-basic.py +38 -0
  99. package/v1 - GRPC/python/demo-executeActionSync.py +32 -0
  100. package/v1 - GRPC/python/demo-flows/flow-demo.json +36 -0
  101. package/v1 - GRPC/python/demo-puzzles/puzzles/puzzle-a.py +19 -0
  102. package/v1 - GRPC/python/demo-puzzles/puzzles/puzzle-b.py +21 -0
  103. package/v1 - GRPC/python/demo-puzzles/puzzles/puzzle-c.py +20 -0
  104. package/v1 - GRPC/python/requirements.txt +7 -0
  105. package/v1 - GRPC/python/setup.py +39 -0
  106. package/v1 - GRPC/python/use-cases/__init__.py +0 -0
package/DEVELOPMENT.md ADDED
@@ -0,0 +1,38 @@
1
+ Based on
2
+
3
+ + [rabbitmq demos](/colabo-business-services/rabbitmq/service-send.js)
4
+ + [similarity.service.ts](/colabo/src/frontend/dev_puzzles/ai-ml/similarity/lib/similarity.service.ts)
5
+ + [backend service](/colabo/src/backend/dev_puzzles/flow/services)
6
+ + [ColaboFlowService](/colabo/src/backend/dev_puzzles/flow/services/index.ts)
7
+ + [demo](/colabo/src/backend/dev_puzzles/flow/services/demo/demo.ts)
8
+ + [ColaboFlowServiceWorker.py](/colabo-business-services/similarity/colaboflow/services/ColaboFlowServiceWorker.py)
9
+ + [similarity_functions.py](/colabo-business-services/similarity/similarity_functions.py)
10
+ + [similarity_functions_wrapper_colaboflow.py](/colabo-business-services/similarity/similarity_functions_wrapper_colaboflow.py)
11
+ + [i-flow puzzles](/colabo/src/isomorphic/dev_puzzles/flow)
12
+ + [@colabo-flow/b-topichat](/colabo/src/backend/dev_puzzles/flow/topichat)
13
+ + [frontend interface to the cFlow service](colabo/src/frontend/dev_puzzles/flow/topichat/lib/colaboFlow-topiChat-form/)
14
+ + [colaboFlow-topiChat-form.component.html](/colabo/src/frontend/dev_puzzles/flow/topichat/lib/colaboFlow-topiChat-form/colaboFlow-topiChat-form.component.html)
15
+
16
+ # Official
17
+
18
+ https://github.com/amqp-node/amqplib
19
+
20
+ https://amqp-node.github.io/amqplib/channel_api.html
21
+
22
+ [examples/tutorials/send.js](https://github.com/amqp-node/amqplib/blob/main/examples/tutorials/send.js)
23
+
24
+ # Problems
25
+
26
+ As we are migrating from CommonJS I had manually change the path for the `@colabo-flow/i-core` puzzle to a correct path in the new branch `colabo-vue3` in [`tsconfig.colabo.json`](../../../tsconfig.colabo.json)
27
+
28
+ ```json5
29
+ "@colabo-flow/i-core": [
30
+ "/Users/mprinc/data/development/colabo-zontik/colabo/src/isomorphic/dev_puzzles/flow/core"
31
+ ],
32
+ "@colabo-flow/i-core/*": [
33
+ "/Users/mprinc/data/development/colabo-zontik/colabo-vue3/src/isomorphic/dev_puzzles/flow/core/*"
34
+ ],
35
+ "@colabo-utils/i-verify": [
36
+ "/Users/mprinc/data/development/colabo-zontik/colabo-vue3/src/isomorphic/dev_puzzles/utils/verify"
37
+ ],
38
+ ```
package/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # Run
2
+
3
+ ## Services
4
+
5
+ ```sh
6
+ # service
7
+ cdcs
8
+ cd puzzles/flow/go
9
+ TS_NODE_PROJECT=./tsconfig.json node --trace-warnings --experimental-specifier-resolution=node --loader $COLABO/ts-esm-loader-with-tsconfig-paths.js lib/go.amqp.service.ts
10
+ ```
11
+
12
+ ## Hosts
13
+
14
+ ```sh
15
+ # boot the host
16
+ cdcs
17
+ cd puzzles/flow/go
18
+ TS_NODE_PROJECT=./tsconfig.json node --trace-warnings --experimental-specifier-resolution=node --loader $COLABO/ts-esm-loader-with-tsconfig-paths.js demo/create-host.ts
19
+
20
+ # TS_NODE_PROJECT=./tsconfig.json node --trace-warnings --experimental-specifier-resolution=node --loader $COLABO/ts-esm-loader-with-tsconfig-paths.js lib/go.amqp.host.ts
21
+
22
+ python3 create_host.py
23
+
24
+ # send a test message with the RabbitMQ CLI
25
+ # https://www.rabbitmq.com/management-cli.html
26
+ rabbitmqadmin publish exchange=amq.default routing_key=test payload="Hello, world from RabbitMQ CLI"
27
+
28
+ # delete the queue `colabo.flow.host.node`
29
+ rabbitmqadmin delete queue name=colabo.flow.host.node
30
+
31
+ # delete all the messages in the `colabo.flow.host.node` queue
32
+ rabbitmqadmin purge queue name=colabo.flow.host.node
33
+
34
+ cd /Users/mprinc/data/development/colabo-zontik/colabo/src/services/puzzles/flow/go
35
+
36
+ python3 create_host_terra.py
37
+ ```
38
+
39
+ # Clients
40
+
41
+ ```sh
42
+ # sending a task request by node client
43
+ # TS_NODE_PROJECT=./tsconfig.json node --trace-warnings --experimental-specifier-resolution=node --loader $COLABO/ts-esm-loader-with-tsconfig-paths.js lib/go.amqp.client.ts
44
+
45
+ TS_NODE_PROJECT=./tsconfig.json node --trace-warnings --experimental-specifier-resolution=node --loader $COLABO/ts-esm-loader-with-tsconfig-paths.js demo/create-client.ts
46
+
47
+ cd /Users/mprinc/data/development/colabo-zontik/colabo/src/services/puzzles/flow/go
48
+
49
+ # sending a task request by python client
50
+ python3 create_client_terra.py
51
+ ```
52
+
53
+ # Messages
54
+
55
+ ```sh
56
+ # delete all the messages in the `colabo.flow.host.node` queue
57
+ rabbitmqadmin purge queue name=colabo.flow.host.node
58
+ ```
59
+
60
+ ## Heartbeat
61
+
62
+ ```sh
63
+ # heartbeat for discovering python test host with a single task: `com.welcometerra.video.ffmpeg-multiple`
64
+ rabbitmqadmin publish exchange=amq.default routing_key=colabo.flow.host.heartbeat payload='{"id": "ColaboFlow-msg:371f4180-5c92-11ed-bc66-96ba02116486", "type": "HEARTBEAT", "requestId": "ColaboFlow-request:371f42f2-5c92-11ed-bc66-96ba02116486", "sender": "host-python-1", "replyTo": null, "proxies": [], "msgReplyChainIds": [], "msg": ["node host with tasks: ['com.welcometerra.video.ffmpeg-multiple']"], "extension": {"id": 2, "queueHost": "colabo.flow.host.python", "language": "PYTHON", "taskIds": ["com.welcometerra.video.ffmpeg-multiple"]}}'
65
+ ```
66
+
67
+ Here is the full message:
68
+
69
+ ```json
70
+ {
71
+ "id": "ColaboFlow-msg:371f4180-5c92-11ed-bc66-96ba02116486",
72
+ "type": "HEARTBEAT",
73
+ "requestId": "ColaboFlow-request:371f42f2-5c92-11ed-bc66-96ba02116486",
74
+ "sender": "host-python-1",
75
+ "replyTo": null,
76
+ "proxies": [],
77
+ "msgReplyChainIds": [],
78
+ "msg": ["node host with tasks: ['com.welcometerra.video.ffmpeg - multiple']"
79
+ ],
80
+ "extension": {
81
+ "id": 2,
82
+ "queueHost": "colabo.flow.host.python",
83
+ "language": "PYTHON",
84
+ "taskIds": ["com.welcometerra.video.ffmpeg-multiple"]
85
+ }
86
+ }
87
+ ```
88
+
89
+ ## process_video
90
+
91
+ ```json
92
+ {
93
+ "userId": 16,
94
+ "videoId": 49,
95
+ "videoFileLocalPath": "/var/folders/f5/s2lwsbwx34728zbv9vd91f4w0000gn/T/tmpzz4ykin9.mp4",
96
+ "first_name": "Sasha",
97
+ "email": "mprinc@gmail.com",
98
+ "username": "mprinc",
99
+ "task_context": {
100
+ "processId": 1,
101
+ "userId": 16,
102
+ "userName": "mprinc",
103
+ "videoId": 49,
104
+ "videoName": "ALWAYS BE SILENT IN FIVE SITUATIONS _ APJ Abdul Kalam Quotes _ Life Quotes - Quotation & Motivation.mp4",
105
+ "name": "process_video",
106
+ "id": 1
107
+ },
108
+ "videoToAudio": false
109
+ }
110
+ ```
package/__init__.py ADDED
File without changes
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env python
2
+ # https://pypi.org/project/pika/
3
+ import pika
4
+ import json
5
+ from yachalk import chalk
6
+ # from dataclasses import replace
7
+ # https://docs.python.org/3/library/uuid.html
8
+ import uuid
9
+ from typing import Any
10
+ import threading
11
+ import asyncio
12
+
13
+ from lib.config import connectConfig
14
+ # from lib.go_amqp_client import run, executeTask, close
15
+ from lib.go_amqp_client import run, executeTask, stop_consuming, close
16
+
17
+ from lib.vos import IColaboFlowClientData
18
+
19
+ clientName = "client-python-1"
20
+ appNameText = f'[{chalk.red.bold("Colabo")}{chalk.blue.bold("Flow")}{chalk.green.bold(".Go")}.{chalk.white.bold(clientName)}]';
21
+
22
+ def appNameTextWithContext(context: str) -> str:
23
+ threadId = threading.get_native_id()
24
+ return f'[[{chalk.blue.bold(threadId)}]{chalk.red.bold("Colabo")}{chalk.blue.bold("Flow")}{chalk.green.bold(".Go")}.{chalk.white.bold(clientName)}:{chalk.yellow.bold(context)}]';
25
+
26
+ clientPython1 = IColaboFlowClientData(
27
+ clientName = clientName,
28
+ appNameText = appNameText,
29
+ appNameTextWithContext = appNameTextWithContext,
30
+ amqpUrl = connectConfig.AMQP_URL,
31
+ queueServiceOrchestrator = connectConfig.ORCHESTRATOR_QUEUE,
32
+
33
+ taskInstances = {},
34
+ )
35
+
36
+ async def main():
37
+ print(f"{appNameTextWithContext('main')} Initializing ColaboFlow")
38
+
39
+ await run(clientPython1)
40
+
41
+ # print(f"{appNameTextWithContext('main')} Launching Task 1")
42
+
43
+ # task1Id: str = "com.welcometerra.video.ffmpeg-combine"
44
+ # task1Input: Any = {
45
+ # "a": 5,
46
+ # "b": 3,
47
+ # }
48
+ # task1OutputPromised = asyncio.create_task(
49
+ # executeTask(clientPython1, task1Id, task1Input)
50
+ # )
51
+
52
+ # print(f"{appNameTextWithContext('main')} Launching Task 2")
53
+
54
+ # task2Id: str = "colabo.flow.demo.reduce"
55
+ # task2Input: Any = {
56
+ # "a": 5,
57
+ # "b": 8,
58
+ # }
59
+ # task2Output = await executeTask(clientPython1, task2Id, task2Input)
60
+ # print(f"{appNameTextWithContext('main')} Task 2 Execution taskOutput: {chalk.blue.bold(task2Output)}")
61
+
62
+ print(f"{appNameTextWithContext('main')} Launching Task 3")
63
+
64
+ task3Id: str = "com.welcometerra.video.ffmpeg-multiple"
65
+ task3Input: Any = {
66
+ "a": 5,
67
+ "b": 5,
68
+ }
69
+ task3Output = await executeTask(clientPython1, task3Id, task3Input)
70
+ print(f"{appNameTextWithContext('main')} Task 3 Execution taskOutput: {chalk.blue.bold(task3Output)}")
71
+
72
+ # task1Output = await task1OutputPromised
73
+ # print(f"{appNameTextWithContext('main')} Task 1 Execution taskOutput: {chalk.blue.bold(task1Output)}")
74
+
75
+ close(clientPython1)
76
+
77
+ try:
78
+ asyncio.run(main())
79
+ except KeyboardInterrupt:
80
+ # extra line to compensate the CTRL+C keystroke
81
+ print(f"")
82
+ print(f"{appNameTextWithContext('main')} keyboard interrupt, _stop_consuming")
83
+ stop_consuming(clientPython1)
84
+ close(hostPython1)
package/create_host.py ADDED
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env python
2
+ # https://pypi.org/project/pika/
3
+ import pika
4
+ import json
5
+ from yachalk import chalk
6
+ from dataclasses import replace
7
+ # https://docs.python.org/3/library/uuid.html
8
+ import uuid
9
+ from typing import Any, Optional, Callable
10
+ import threading
11
+ import asyncio
12
+
13
+ from dacite import from_dict, Config
14
+
15
+ from lib.config import connectConfig
16
+ # from lib.go_amqp_host import run, executeTask, close
17
+ from lib.go_amqp_host import run, registerTaskExecutor, registerTask, sendHeartbeatToHost, close
18
+
19
+ from lib.vos import IColaboFlowHostData
20
+ from lib.executor_vos import ITaskExecutor, EExecutingEnvironment, IExecutorImplementationReference, IFlowTask, EFlowTaskType, EExecutingEnvironment, EFlowPlaceType, IExecutorReference
21
+
22
+ hostName = "host-python-1"
23
+ appNameText = f'[{chalk.red.bold("Colabo")}{chalk.blue.bold("Flow")}{chalk.green.bold(".Go")}.{chalk.white.bold(hostName)}]';
24
+
25
+ def appNameTextWithContext(context: str) -> str:
26
+ threadId = threading.get_native_id()
27
+ return f'[[{chalk.blue.bold(threadId)}]{chalk.red.bold("Colabo")}{chalk.blue.bold("Flow")}{chalk.green.bold(".Go")}.{chalk.white.bold(hostName)}:{chalk.yellow.bold(context)}]';
28
+
29
+ hostPython1 = IColaboFlowHostData(
30
+ hostName = hostName,
31
+ appNameText = appNameText,
32
+ appNameTextWithContext = appNameTextWithContext,
33
+ amqpUrl = connectConfig.AMQP_URL,
34
+ queueHost = connectConfig.HOST_QUEUE,
35
+ queueHostHeartbeat = connectConfig.HOST_HEARTBEAT_QUEUE,
36
+ queueServiceOrchestrator = connectConfig.ORCHESTRATOR_QUEUE,
37
+ )
38
+
39
+ from dataclasses import dataclass
40
+
41
+ @dataclass
42
+ class IExecutorMultipleInput():
43
+ a: int
44
+ b: int
45
+
46
+ async def asyncExecutor_executeMultiple(inputAny: Any) -> int:
47
+ input: IExecutorMultipleInput = from_dict(data_class=IExecutorMultipleInput, data=inputAny)
48
+ if not input:
49
+ print(f"[asyncExecutor_executeBar] Missing input")
50
+ return -1
51
+
52
+ print(f"[asyncExecutor_executeBar] a: {input.a}, b: {input.b}")
53
+ asyncio.sleep(2)
54
+ return input.a * input.b;
55
+
56
+ executorMultiple: ITaskExecutor = ITaskExecutor(
57
+ id = "com.welcometerra.video.ffmpeg-multiple",
58
+ description = "Multiple ffmpeg videos",
59
+ # TODO: In future it should be isomorphic-like: should work on frontend if provided, on backend if provided (with CLI flow overview), or isomorphic if nothing provide
60
+ environment = EExecutingEnvironment.BACKEND,
61
+ reference = IExecutorImplementationReference(
62
+ async_method = asyncExecutor_executeMultiple,
63
+ ),
64
+ )
65
+
66
+ taskMultiple: IFlowTask = IFlowTask(
67
+ id = "com.welcometerra.video.ffmpeg-multiple",
68
+ type = EFlowTaskType.SCRIPT,
69
+ description = "Demo multiplying numbers",
70
+ executorRef = IExecutorReference(
71
+ id = executorMultiple.id,
72
+ environment = EExecutingEnvironment.BACKEND,
73
+ ),
74
+ )
75
+ print(f"taskMultiple: {taskMultiple}")
76
+
77
+ registerTaskExecutor(hostPython1, executorMultiple);
78
+ registerTask(hostPython1, taskMultiple);
79
+
80
+ async def main():
81
+ print(f"{appNameTextWithContext('main')} Initializing ColaboFlow")
82
+
83
+ await run(hostPython1)
84
+ # we need it to keep the asyncio loop running, as otherwise the loop would stop triggering
85
+ # for example `await asyncio.sleep(1)` in the `go_amqp_host.py:sendHeartbeatsToHost()` would never wake up
86
+ while hostPython1.running:
87
+ # print(f"{appNameTextWithContext('main')} looping in main ...")
88
+ await asyncio.sleep(1)
89
+
90
+ asyncio.run(main())
91
+
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env python
2
+ # https://pypi.org/project/pika/
3
+ import pika
4
+ import json
5
+ from yachalk import chalk
6
+ from dataclasses import replace
7
+ # https://docs.python.org/3/library/uuid.html
8
+ import uuid
9
+ from typing import Any, Optional, Callable
10
+ import threading
11
+ import asyncio
12
+
13
+ from lib.config import connectConfig
14
+ # from lib.go_amqp_host import run, executeTask, close
15
+ from lib.go_amqp_host import run, registerTaskExecutor, registerTask, sendHeartbeatToHost, stop_consuming, close
16
+
17
+ from lib.vos import IColaboFlowHostData
18
+ from lib.executor_vos import ITaskExecutor, EExecutingEnvironment, IExecutorImplementationReference, IFlowTask, EFlowTaskType, EExecutingEnvironment, EFlowPlaceType, IExecutorReference
19
+
20
+ # https://stackoverflow.com/a/53713336/257561
21
+ # https://github.com/konradhalas/dacite
22
+ from dacite import from_dict, Config
23
+
24
+ hostName = "host-python-1"
25
+ appNameText = f'[{chalk.red.bold("Colabo")}{chalk.blue.bold("Flow")}{chalk.green.bold(".Go")}.{chalk.white.bold(hostName)}]';
26
+
27
+ def appNameTextWithContext(context: str) -> str:
28
+ threadId = threading.get_native_id()
29
+ return f'[ (thread:{chalk.blue.bold(threadId)}) {chalk.red.bold("Colabo")}{chalk.blue.bold("Flow")}{chalk.green.bold(".Go")}.{chalk.white.bold(hostName)}:{chalk.yellow.bold(context)}]';
30
+
31
+ hostPython1 = IColaboFlowHostData(
32
+ hostName = hostName,
33
+ appNameText = appNameText,
34
+ appNameTextWithContext = appNameTextWithContext,
35
+ amqpUrl = connectConfig.AMQP_URL,
36
+ queueHost = connectConfig.HOST_QUEUE,
37
+ queueHostHeartbeat = connectConfig.HOST_HEARTBEAT_QUEUE,
38
+ queueServiceOrchestrator = connectConfig.ORCHESTRATOR_QUEUE,
39
+ sendHeartbeat = True,
40
+ listenForOrchestratorRequests = True,
41
+ processOrchestratorTaskExecuteRequests = True,
42
+ )
43
+
44
+ from dataclasses import dataclass
45
+
46
+ @dataclass
47
+ class IExecutorMultipleInput():
48
+ a: int
49
+ b: int
50
+
51
+ async def asyncExecutor_executeMultiple(inputAny: Any) -> int:
52
+ input: IExecutorMultipleInput = from_dict(data_class=IExecutorMultipleInput, data=inputAny)
53
+ if not input:
54
+ print(f"[asyncExecutor_executeBar] Missing input")
55
+ return -1
56
+
57
+ print(f"[asyncExecutor_executeBar] a: {input.a}, b: {input.b}")
58
+ asyncio.sleep(2)
59
+ return input.a * input.b;
60
+
61
+ executorMultiple: ITaskExecutor = ITaskExecutor(
62
+ id = "com.welcometerra.video.ffmpeg-multiple",
63
+ description = "Multiple ffmpeg videos",
64
+ # TODO: In future it should be isomorphic-like: should work on frontend if provided, on backend if provided (with CLI flow overview), or isomorphic if nothing provide
65
+ environment = EExecutingEnvironment.BACKEND,
66
+ reference = IExecutorImplementationReference(
67
+ method = asyncExecutor_executeMultiple,
68
+ ),
69
+ )
70
+
71
+ taskMultiple: IFlowTask = IFlowTask(
72
+ id = "com.welcometerra.video.ffmpeg-multiple",
73
+ type = EFlowTaskType.SCRIPT,
74
+ description = "Demo multiplying numbers",
75
+ executorRef = IExecutorReference(
76
+ id = executorMultiple.id,
77
+ environment = EExecutingEnvironment.BACKEND,
78
+ ),
79
+ )
80
+ print(f"taskMultiple: {taskMultiple}")
81
+
82
+ registerTaskExecutor(hostPython1, executorMultiple);
83
+ registerTask(hostPython1, taskMultiple);
84
+
85
+ async def main():
86
+ print(f"{appNameTextWithContext('main')} Initializing ColaboFlow")
87
+
88
+ await run(hostPython1)
89
+ # we need it to keep the asyncio loop running, as otherwise the loop would stop triggering
90
+ # for example `await asyncio.sleep(1)` in the `go_amqp_host.py:sendHeartbeatsToHost()` would never wake up
91
+ while hostPython1.running:
92
+ # print(f"{appNameTextWithContext('main')} looping in main ...")
93
+ await asyncio.sleep(1)
94
+
95
+ try:
96
+ asyncio.run(main())
97
+ except KeyboardInterrupt:
98
+ # extra line to compensate the CTRL+C keystroke
99
+ print(f"")
100
+ print(f"{appNameTextWithContext('main')} keyboard interrupt, _stop_consuming")
101
+ stop_consuming(hostPython1)
102
+ close(hostPython1)
103
+
File without changes
@@ -0,0 +1,51 @@
1
+ import chalk from "chalk";
2
+
3
+ import { clientClose, clientExecuteTask, clientRun } from "../lib/go.amqp.client";
4
+
5
+ import { connectConfig } from "../lib/config";
6
+ import { IColaboFlowClientData } from "../lib/vos";
7
+
8
+ const appNameText = `[${chalk.red.bold("Colabo")}${chalk.blue.bold("Flow")}${chalk.green.bold(".Go")}${chalk.green.yellow("client")}]`;
9
+
10
+ const clientNode1: IColaboFlowClientData = {
11
+ clientName: "client-node-1",
12
+ amqpUrl: connectConfig.AMQP_URL,
13
+ queueServiceOrchestrator: connectConfig.ORCHESTRATOR_QUEUE,
14
+
15
+ taskInstances: {},
16
+ };
17
+
18
+ await clientRun(clientNode1);
19
+
20
+ console.log(`${appNameText} Launching Task 1`);
21
+ const task1Id: string = "com.welcometerra.video.ffmpeg-combine";
22
+ const task1Input: any = {
23
+ a: 5,
24
+ b: 3,
25
+ };
26
+ const task1OutputPromised: Promise<any> = clientExecuteTask(clientNode1, task1Id, task1Input);
27
+
28
+ console.log(`${appNameText} Launching Task 2`);
29
+ const task2Id: string = "colabo.flow.demo.reduce";
30
+ const task2Input: any = {
31
+ a: 5,
32
+ b: 8,
33
+ };
34
+ const task2Output: any = await clientExecuteTask(clientNode1, task2Id, task2Input);
35
+ console.log(`${appNameText} Task 2 Execution taskOutput: ${chalk.blueBright(JSON.parse(task2Output))}`);
36
+
37
+ console.log(`${appNameText} Launching Task 3`);
38
+ const task3Id: string = "com.welcometerra.video.ffmpeg-multiple";
39
+ const task3Input: any = {
40
+ a: 5,
41
+ b: 5,
42
+ };
43
+ const task3Output: any = await clientExecuteTask(clientNode1, task3Id, task3Input);
44
+ console.log(`${appNameText} Task 3 Execution taskOutput: ${chalk.blueBright(JSON.parse(task3Output))}`);
45
+
46
+ const task1Output: any = await task1OutputPromised;
47
+ console.log(`${appNameText} Task 1 Execution taskOutput: ${chalk.blueBright(JSON.parse(task1Output))}`);
48
+
49
+ await clientClose(clientNode1);
50
+
51
+ process.exit(0);
@@ -0,0 +1,136 @@
1
+ import { EExecutingEnvironment, EFlowPlaceType, EFlowTaskType, IFlowTask, ITaskExecutor } from "@colabo-flow/i-core/vos";
2
+
3
+ import { hostSetTitles, hostRegisterTaskExecutor, hostRegisterTask, hostRun } from "../lib/go.amqp.host";
4
+ import { IColaboFlowHostData } from "../lib/vos";
5
+
6
+ import { connectConfig } from "../lib/config";
7
+
8
+ const asyncExecutor_executeFoo = async (video_path: string): Promise<void> => {
9
+ console.log(`[asyncExecutor_executeFoo] video_path: ${video_path}`);
10
+ };
11
+
12
+ interface IExecutorCombineInput {
13
+ a: number;
14
+ b: number;
15
+ }
16
+
17
+ const asyncExecutor_executeCombine = async (input: IExecutorCombineInput): Promise<number> => {
18
+ if(!input) {
19
+ console.log(`[asyncExecutor_executeBar] Missing input`);
20
+ return -1;
21
+ }
22
+
23
+ console.log(`[asyncExecutor_executeBar] a: ${input.a}, b: ${input.b}`);
24
+ // await new Promise((r) => setTimeout(r, 2000));
25
+ return input.a + input.b;
26
+ };
27
+
28
+ interface IExecutorReduceInput {
29
+ a: number;
30
+ b: number;
31
+ }
32
+ const asyncExecutor_executeReduce = async (input: IExecutorReduceInput): Promise<number> => {
33
+ if(!input) {
34
+ console.log(`[asyncExecutor_executeMinus] Missing input`);
35
+ return -1;
36
+ }
37
+ console.log(`[asyncExecutor_executeMinus] a: ${input.a}, b: ${input.b}`);
38
+ // await new Promise((r) => setTimeout(r, 2000));
39
+ return input.a - input.b;
40
+ };
41
+
42
+ const executorFoo: ITaskExecutor = {
43
+ id: "com.welcometerra.video.ffmpeg",
44
+ description: "Process ffmpeg videos",
45
+ // TODO: In future it should be isomorphic-like: should work on frontend if provided, on backend if provided (with CLI flow overview), or isomorphic if nothing provide
46
+ environment: EExecutingEnvironment.BACKEND,
47
+ reference: {
48
+ method: asyncExecutor_executeFoo,
49
+ },
50
+ };
51
+
52
+ const executorCombine: ITaskExecutor = {
53
+ id: "com.welcometerra.video.ffmpeg-combine",
54
+ description: "Combine ffmpeg videos",
55
+ // TODO: In future it should be isomorphic-like: should work on frontend if provided, on backend if provided (with CLI flow overview), or isomorphic if nothing provide
56
+ environment: EExecutingEnvironment.BACKEND,
57
+ reference: {
58
+ method: asyncExecutor_executeCombine,
59
+ },
60
+ };
61
+
62
+ const executorReduce: ITaskExecutor = {
63
+ id: "colabo.flow.demo.reduce",
64
+ description: "It demos colabo flow tasks",
65
+ // TODO: In future it should be isomorphic-like: should work on frontend if provided, on backend if provided (with CLI flow overview), or isomorphic if nothing provide
66
+ environment: EExecutingEnvironment.BACKEND,
67
+ reference: {
68
+ method: asyncExecutor_executeReduce,
69
+ },
70
+ };
71
+
72
+ const taskFoo: IFlowTask = {
73
+ id: "com.welcometerra.video.ffmpeg",
74
+ type: EFlowTaskType.SCRIPT,
75
+ executorRef: {
76
+ environment: EExecutingEnvironment.BACKEND,
77
+ id: executorFoo.id,
78
+ },
79
+ placeType: EFlowPlaceType.TASK,
80
+ inputs: [],
81
+ outputs: [],
82
+ inoutputs: [],
83
+ };
84
+
85
+ const taskCombine: IFlowTask = {
86
+ id: "com.welcometerra.video.ffmpeg-combine",
87
+ type: EFlowTaskType.SCRIPT,
88
+ executorRef: {
89
+ environment: EExecutingEnvironment.BACKEND,
90
+ id: executorCombine.id,
91
+ },
92
+ placeType: EFlowPlaceType.TASK,
93
+ inputs: [],
94
+ outputs: [],
95
+ inoutputs: [],
96
+ };
97
+
98
+ const taskReduce: IFlowTask = {
99
+ id: "colabo.flow.demo.reduce",
100
+ type: EFlowTaskType.SCRIPT,
101
+ executorRef: {
102
+ environment: EExecutingEnvironment.BACKEND,
103
+ id: executorReduce.id,
104
+ },
105
+ placeType: EFlowPlaceType.TASK,
106
+ inputs: [],
107
+ outputs: [],
108
+ inoutputs: [],
109
+ };
110
+
111
+ const hostNode1: IColaboFlowHostData = {
112
+ hostname: "host-node-1",
113
+ amqpUrl: connectConfig.AMQP_URL,
114
+ queueHost: connectConfig.HOST_NODE_QUEUE,
115
+ queueHostHeartbeat: connectConfig.HOST_HEARTBEAT_QUEUE,
116
+
117
+ chHostHeartbeat: undefined,
118
+
119
+ taskExecutorsAvailable: {},
120
+ tasksAvailable: {},
121
+ taskInstances: {},
122
+ runningTaskInstancesInfos: {},
123
+ finalizedTaskInstancesInfos: {},
124
+ };
125
+
126
+ hostSetTitles(hostNode1);
127
+
128
+ hostRegisterTaskExecutor(hostNode1, executorFoo);
129
+ hostRegisterTaskExecutor(hostNode1, executorCombine);
130
+ hostRegisterTaskExecutor(hostNode1, executorReduce);
131
+
132
+ hostRegisterTask(hostNode1, taskFoo);
133
+ hostRegisterTask(hostNode1, taskCombine);
134
+ hostRegisterTask(hostNode1, taskReduce);
135
+
136
+ hostRun(hostNode1);
@@ -0,0 +1,26 @@
1
+ # NOTE: not working yet
2
+ # https://pypi.org/project/pika/
3
+ import pika
4
+
5
+ amqp_server = "localhost"
6
+ queue_name = "test"
7
+
8
+ parameters = (
9
+ pika.ConnectionParameters(
10
+ host=amqp_server,
11
+ connection_attempts=5,
12
+ retry_delay=1
13
+ )
14
+ )
15
+
16
+ print(f"Connecting to server: {amqp_server}")
17
+ connection = pika.BlockingConnection()
18
+
19
+ channel = connection.channel()
20
+
21
+ msg = b'Test message.'
22
+ print(f'Sending message to the queue "{amqp_server}": {msg}')
23
+ channel.basic_publish(exchange=queue_name, routing_key=queue_name,
24
+ body=msg)
25
+
26
+ connection.close()