Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ AUTH0_CLIENT_ID=<FILL_IN>
AUTH0_CLIENT_SECRET=<FILL_IN>
AUTH0_DOMAIN=<FILL_IN>

CELERY_BROKER_URL=redis://redis:6379/0
CELERY_RESULT_BACKEND=redis://redis:6379/0

DJANGO_HOST=<FILL_IN_WITH_MACHINE_IP_ADDRESS>
DJANGO_SUPERUSER_EMAIL=<FILL_IN_WITH_ANY_EMAIL>
DJANGO_SUPERUSER_USERNAME=<FILL_IN_WITH_ANY_USERNAME>
Expand Down
16 changes: 15 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ services:
networks:
- apinet

redisinsight:
container_name: amui-redisinsight
image: redislabs/redisinsight:latest
ports:
- 5540:5540
volumes:
- redisinsight_data:/data
networks:
- apinet
# extra_hosts:
# - "host.docker.internal:host-gateway"

pgadmin:
container_name: amui-pgadmin
image: dpage/pgadmin4
Expand Down Expand Up @@ -99,6 +111,7 @@ services:
flow3d:
container_name: amui-flow3d
environment:
- CELERY_RESULT_BACKEND=${CELERY_RESULT_BACKEND}
- QT_QPA_PLATFORM=minimal
build:
context: ./services/flow3d
Expand All @@ -109,7 +122,7 @@ services:
- REDHAT_USERNAME=${REDHAT_USERNAME}
- REDHAT_PASSWORD=${REDHAT_PASSWORD}

# Uncomment for production
# Uncomment for non-development
# command: bash ./entrypoint.sh
tty: true
depends_on:
Expand Down Expand Up @@ -137,6 +150,7 @@ volumes:
web_node_modules:
flow3d_out:
flow3d_venv:
redisinsight_data:

networks:
apinet:
Expand Down
4 changes: 0 additions & 4 deletions services/api/api/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@

# Load task modules from all registerd Django apps.
app.autodiscover_tasks()

@app.task(bind=True, ignore_result=True)
def debug_task(self):
print(f"Request: {self.request!r}")
9 changes: 6 additions & 3 deletions services/api/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"django.contrib.staticfiles",
# Third Party
"corsheaders",
"django_filters",
"django_extensions",
"django_filters",
"rest_framework",
# Apps
"auth0",
Expand Down Expand Up @@ -204,5 +204,8 @@
USE_X_FORWARDED_HOST = True

# Celery
CELERY_BROKER_URL = 'redis://redis:6379/0'
CELERY_BROKER_BACKEND = 'redis://redis:6379/0'
CELERY_BROKER_URL = os.environ.get("CELERY_BROKER_URL")
CELERY_RESULT_BACKEND = os.environ.get("CELERY_RESULT_BACKEND")
CELERY_IGNORE_RESULT = False
CELERY_TRACK_STARTED = True
CELERY_TASK_IGNORE_RESULT = False
1 change: 1 addition & 0 deletions services/api/flow3d/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

urlpatterns = [
path("flow3d/test_task/", views.Flow3DTestTask.as_view()),
path("flow3d/test_task/<str:task_id>/", views.Flow3DTestTask.as_view()),
]

urlpatterns = format_suffix_patterns(urlpatterns)
13 changes: 11 additions & 2 deletions services/api/flow3d/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# from flow3d.tasks import add
from api.celery import app

import time

class Flow3DTestTask(APIView):

permission_classes = (AllowAny,)
Expand All @@ -17,5 +19,12 @@ def post(self, request):
x = request.data.get("x")
y = request.data.get("y")
# add.delay(x, y)
app.send_task('flow3d.tasks.add', args=[x, y])
return Response({"message": "task is processing"}, status=status.HTTP_201_CREATED)
task = app.send_task('flow3d.tasks.add', args=[x, y])
return Response({"task_id": task.id }, status=status.HTTP_201_CREATED)

def get(self, request, task_id):
task_result = app.AsyncResult(task_id)
result = task_result.result
status = task_result.status
print(result, status)
return Response({"task_id": task_id, "status": status, "result": result})
3 changes: 2 additions & 1 deletion services/flow3d/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ COPY ./out ./out
#################
# Celery Worker #
#################

COPY ./entrypoint.sh .
COPY ./flow3d ./flow3d
COPY ./worker ./worker

# Runs 'entrypoint.sh' script.
# https://stackoverflow.com/a/50276037/10521456
Expand Down
3 changes: 2 additions & 1 deletion services/flow3d/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
echo "Starting Worker..."
. venv/bin/activate
cd worker
exec celery -A app worker --loglevel=info

exec celery -A app worker --loglevel=info --pool=solo -E
3 changes: 3 additions & 0 deletions services/flow3d/worker/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

app = Celery('app', broker='redis://redis:6379/0')

app.conf.task_track_started = True
app.conf.task_ignore_result = False

# Needed to discover tasks
import flow3d

Expand Down
17 changes: 16 additions & 1 deletion services/web/src/flow3d/TestTaskForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Box, Button, TextField } from '@mui/material';
import { ChangeEvent, FC, useState } from 'react';

// API
import { postFlow3DTestTask } from './_api';
import { getFlow3DTestTask, postFlow3DTestTask } from './_api';

interface Request {
x: string;
Expand All @@ -21,6 +21,8 @@ const TestTaskForm: FC = () => {
y: '',
});

const [taskId, setTaskId] = useState('')

// Callbacks
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target;
Expand All @@ -34,6 +36,10 @@ const TestTaskForm: FC = () => {
await postFlow3DTestTask(request);
};

const handleClickTaskResult = async () => {
await getFlow3DTestTask(taskId);
};

return (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: "1em" }}>
<TextField
Expand All @@ -51,6 +57,15 @@ const TestTaskForm: FC = () => {
<Button onClick={handleClick} variant="contained">
Submit
</Button>
<TextField
label="Task Result"
name="task_result"
onChange={(e) => setTaskId(e.target.value)}
value={taskId}
/>
<Button onClick={handleClickTaskResult} variant="contained">
Submit
</Button>
</Box>
);
};
Expand Down
11 changes: 11 additions & 0 deletions services/web/src/flow3d/_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ export const postFlow3DTestTask = async (xy: XY) => {
return null;
}
};

export const getFlow3DTestTask = async (task_id: string) => {
try {
const response = await axios.get(`flow3d/test_task/${task_id}/`);
const { data, status: code } = response;
return { data, code };
} catch (error) {
console.log(error)
return null;
}
};
Loading