Skip to content

Commit b070f01

Browse files
authored
Merge pull request #19 from mmacata/actinia-worker-http-launcher
Add actinia-worker-http-launcher
2 parents a914911 + 7e768cb commit b070f01

File tree

16 files changed

+155
-68
lines changed

16 files changed

+155
-68
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
exclude = .git,.pycache,build,.eggs
88

99
per-file-ignores =
10+
./tests/actinia_worker_http_launcher.py: E501
1011
./tests/cloudevent_receiver_server.py: E501
1112
# remove when implemented:
1213
./src/actinia_cloudevent_plugin/api/cloudevent.py: E501

.vscode/tasks.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@
1717
"command": "docker compose -f docker/docker-compose-vscode.yml up -d --build --force-recreate event-receiver-server",
1818
"isBackground": true
1919
},
20+
{
21+
"label": "start-actinia-worker-http-launcher",
22+
"type": "shell",
23+
"command": "docker compose -f docker/docker-compose-vscode.yml up -d --build --force-recreate actinia-worker-http-launcher",
24+
"isBackground": true
25+
},
2026
{
2127
"type": "docker-run",
2228
"label": "docker-run: debug",
2329
"dependsOn": [
2430
"docker-build",
25-
"start-cloudevent-receiver-dummy-server"
31+
"start-cloudevent-receiver-dummy-server",
32+
"start-actinia-worker-http-launcher"
2633
],
2734
"python": {
2835
"module": "flask",

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ dist:
1919
python3 setup.py dist
2020

2121
test:
22-
./tests_with_cloudevent_receiver.sh
22+
pytest
2323

2424
unittest:
25-
./tests_with_cloudevent_receiver.sh unittest
25+
pytest -m "unittest"
2626

2727
devtest:
28-
./tests_with_cloudevent_receiver.sh dev
28+
pytest -m "dev"
2929

3030
integrationtest:
31-
./tests_with_cloudevent_receiver.sh integrationtest
31+
pytest -m "integrationtest"

config/mount/sample.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[ACTINIA]
2-
processing_base_url = http://actinia-core:8088/api/v3
2+
enqueue_job_base_url = http://actinia-core:8088/api/v3
33
use_actinia_modules = True
44
user = actinia-gdi
55
password = actinia-gdi
6+
worker_http_launcher_url = http://actinia-worker-http-launcher:8000/launch
67

78
[EVENTRECEIVER]
89
url = http://event-receiver-server:3000/

docker/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ RUN pip3 install --no-cache-dir gunicorn && \
1818
pip3 install --no-cache-dir setuptools pwgen==0.8.2.post0 pytest==8.3.5 pytest-cov==6.0.0 python-dotenv
1919

2020
COPY . /src/actinia-cloudevent-plugin/
21-
RUN pip3 install --no-cache-dir -e /src/actinia-cloudevent-plugin/ && \
22-
# For tests:
23-
chmod a+x /src/actinia-cloudevent-plugin/tests_with_cloudevent_receiver.sh
21+
RUN pip3 install --no-cache-dir -e /src/actinia-cloudevent-plugin/
2422

2523
RUN echo "RUNNING_SINCE=`date`" > /src/.env
2624

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM alpine:3.23
2+
3+
RUN apk update; \
4+
apk add --no-cache python3 python3-dev make
5+
ENV PATH="/opt/venv/bin:$PATH"
6+
RUN /usr/bin/python -m venv --system-site-packages --without-pip /opt/venv
7+
RUN python -m ensurepip && pip3 install --no-cache-dir --upgrade pip
8+
9+
RUN pip install --no-cache-dir --upgrade fastapi[standard] docker
10+
11+
COPY tests/actinia_worker_http_launcher.py /src/app.py
12+
13+
WORKDIR /src
14+
CMD ["fastapi", "run", "/src/app.py", "--port", "8000"]

docker/docker-compose-vscode.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ services:
99
networks:
1010
actinia-dev:
1111

12+
actinia-worker-http-launcher:
13+
container_name: actinia-worker-http-launcher
14+
build:
15+
context: ..
16+
dockerfile: docker/Dockerfile_actinia-worker-http-launcher
17+
ports:
18+
- "8000:8000"
19+
volumes:
20+
- /var/run/docker.sock:/var/run/docker.sock
21+
networks:
22+
actinia-dev:
23+
1224
networks:
1325
actinia-dev:
1426
name: actinia-docker_actinia-dev

docker/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ services:
2323
dockerfile: docker/Dockerfile_eventreceiver
2424

2525
actinia-core:
26-
image: mundialis/actinia:2.12.2
26+
image: mundialis/actinia:2.13.0
2727
depends_on:
2828
- valkey
2929

ruff.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# N802 Function name should be lowercase
88
# N816 Variable in global scope should not be mixedCas
99
# PLC0415 import-outside-top-level
10+
# PLR0912 Too many branches (13 > 12)
1011
# PLR0913 too-many-arguments (of function definition)
1112
# PLR0917 too-many-positional-arguments (of function definition)
1213
# PLR2004 magic-value-comparison (unnamed numerical constants ("magic") values)
@@ -23,7 +24,7 @@ lint.ignore = ["ANN001", "ANN201", "ANN202", "E501", "FA102", "N802", "N816", "P
2324
[lint.per-file-ignores]
2425
"tests/testsuite.py" = [ "PLC0415",]
2526
"src/actinia_cloudevent_plugin/resources/logging.py" = ["A005",]
26-
"src/actinia_cloudevent_plugin/resources/config.py" = ["SIM102","S105"]
27+
"src/actinia_cloudevent_plugin/resources/config.py" = ["PLR0912", "SIM102","S105"]
2728
"tests/integrationtests/test_cloudevent.py" = ["PLR2004",]
2829
"tests/cloudevent_receiver_server.py" = ["S104"]
2930
"tests/integrationtests/test_hook.py" = ["PLR2004",]

src/actinia_cloudevent_plugin/api/cloudevents.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from actinia_cloudevent_plugin.model.response_models import (
2626
SimpleStatusCodeResponseModel,
2727
)
28-
from actinia_cloudevent_plugin.resources.config import EVENTRECEIVER
28+
from actinia_cloudevent_plugin.resources.config import ACTINIA, EVENTRECEIVER
2929
from actinia_cloudevent_plugin.resources.logging import log
3030

3131

@@ -62,6 +62,7 @@ def post(self) -> SimpleStatusCodeResponseModel:
6262
# With received process chain start actinia process + return cloudevent
6363
actinia_resp = start_actinia_job(event_received)
6464
queue_name = actinia_resp["queue"]
65+
resource_id = actinia_resp["resource_id"]
6566

6667
try:
6768
if queue_name == "local":
@@ -70,15 +71,12 @@ def post(self) -> SimpleStatusCodeResponseModel:
7071
# job is processed directly.
7172
log.info("No need to start actinia-worker")
7273
else:
73-
pass
74-
# TODO: Send event to JobSink
75-
# TODO: Configure JobSink URL
76-
# url = TODO
77-
# new_event = send_binary_cloud_event(
78-
# event_received,
79-
# queue_name,
80-
# url,
81-
# )
74+
url = f"{ACTINIA.worker_http_launcher_url}/{queue_name}"
75+
new_event = send_binary_cloud_event(
76+
event_received,
77+
queue_name,
78+
url,
79+
)
8280

8381
# Send event to configured broker
8482
url = EVENTRECEIVER.url
@@ -88,11 +86,15 @@ def post(self) -> SimpleStatusCodeResponseModel:
8886
actinia_resp["queue"],
8987
url,
9088
)
91-
return SimpleStatusCodeResponseModel(
92-
status=204,
93-
message=self.msg.replace("<EVENT1>", event_received["id"])
89+
response = {
90+
"status": 201,
91+
"message": self.msg.replace("<EVENT1>", event_received["id"])
9492
.replace("<EVENT2>", new_event["id"])
9593
.replace("<ACTINIA_JOB>", queue_name),
96-
)
94+
"actinia_queue_name": queue_name,
95+
"actinia_job": resource_id,
96+
}
97+
return make_response(jsonify(response), 201)
98+
9799
except ConnectionError as e:
98100
return f"Connection ERROR when returning cloudevent: {e}"

0 commit comments

Comments
 (0)