Skip to content

Commit

Permalink
Fix/v2 log storage aws location (#1024)
Browse files Browse the repository at this point in the history
* Fix S3 example

* test sub-task log storage fix

* Fix initiator

* PEP

* Updated Package Requirements: gunicorn==22.0.0 sqlparse==0.5.0

---------

Co-authored-by: awsbuild <[email protected]>
  • Loading branch information
sambles and awsbuild authored Apr 23, 2024
1 parent 338b85a commit f9e9894
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
34 changes: 29 additions & 5 deletions compose/s3.docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ x-oasis-env: &server-env
OASIS_AWS_S3_ENDPOINT_URL: "http://localstack-s3:4572"
OASIS_AWS_ACCESS_KEY_ID: foobar
OASIS_AWS_SECRET_ACCESS_KEY: foobar
OASIS_AWS_LOCATION: 'oasis/server'

x-worker-env: &worker-env
OASIS_DEBUG: 1
Expand All @@ -46,12 +47,13 @@ x-worker-env: &worker-env
OASIS_RABBIT_PORT: 5672
OASIS_RABBIT_USER: rabbit
OASIS_RABBIT_PASS: rabbit
# S3
# S3
OASIS_STORAGE_TYPE: S3
OASIS_AWS_BUCKET_NAME: example-bucket
OASIS_AWS_S3_ENDPOINT_URL: "http://localstack-s3:4572"
OASIS_AWS_ACCESS_KEY_ID: foobar
OASIS_AWS_SECRET_ACCESS_KEY: foobar
OASIS_AWS_LOCATION: 'oasis/worker'

services:
localstack-s3:
Expand Down Expand Up @@ -125,20 +127,42 @@ services:
- broker
environment:
<<: *server-env
worker:
v1-worker:
restart: always
image: ${WORKER_IMG:-coreoasis/model_worker}:${WORKER_TAG:-dev}
build:
context: .
dockerfile: Dockerfile.model_worker
links:
- celery-db
- broker:mybroker
environment:
<<: *worker-env
OASIS_MODEL_SUPPLIER_ID: OasisLMF
OASIS_MODEL_ID: PiWind
OASIS_MODEL_VERSION_ID: 'v1'
OASIS_RUN_MODE: v1
volumes:
- ${OASIS_MODEL_DATA_DIR:-./data/static}:/home/worker/model:rw
- ../src/model_execution_worker:/home/worker/src/model_execution_worker
v2-worker:
restart: always
image: ${WORKER_IMG:-coreoasis/model_worker}:${WORKER_TAG:-dev}
build:
context: .
dockerfile: Dockerfile.model_worker
links:
- celery-db
- broker:mybroker
environment:
<<: *worker-env
OASIS_MODEL_SUPPLIER_ID: OasisLMF
OASIS_MODEL_ID: PiWind
OASIS_MODEL_VERSION_ID: 1
OASIS_RUN_MODE: ${WORKER_API_VER:-v1}
OASIS_MODEL_VERSION_ID: 'v2'
OASIS_RUN_MODE: v2
volumes:
- ../:/home/worker/model
- ${OASIS_MODEL_DATA_DIR:-./data/static}:/home/worker/model:rw
- ../src/model_execution_worker:/home/worker/src/model_execution_worker
server-db:
restart: always
image: postgres
Expand Down
5 changes: 3 additions & 2 deletions requirements-server.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fsspec==2024.2.0
# oasis-data-manager
greenlet==2.0.2
# via sqlalchemy
gunicorn==20.1.0
gunicorn==22.0.0
# via -r requirements-server.in
hiredis==2.2.2
# via aioredis
Expand Down Expand Up @@ -217,6 +217,7 @@ packaging==23.0
# via
# drf-yasg
# fastparquet
# gunicorn
# ods-tools
pandas==2.1.4
# via
Expand Down Expand Up @@ -293,7 +294,7 @@ six==1.16.0
# service-identity
sqlalchemy==1.4.47
# via -r requirements-server.in
sqlparse==0.4.4
sqlparse==0.5.0
# via
# django
# django-debug-toolbar
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ geopandas==0.12.2
# via oasislmf
greenlet==2.0.2
# via sqlalchemy
gunicorn==20.1.0
gunicorn==22.0.0
# via -r ./requirements-server.in
hiredis==2.2.2
# via aioredis
Expand Down Expand Up @@ -352,6 +352,7 @@ packaging==23.0
# drf-yasg
# fastparquet
# geopandas
# gunicorn
# ods-tools
# pyproject-api
# pytest
Expand Down Expand Up @@ -521,7 +522,7 @@ sqlalchemy==1.4.47
# via
# -r ./requirements-server.in
# -r ./requirements-worker.in
sqlparse==0.4.4
sqlparse==0.5.0
# via
# django
# django-debug-toolbar
Expand Down
17 changes: 6 additions & 11 deletions src/server/oasisapi/analyses/v2_api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def record_input_files(self, result, analysis_id=None, initiator_id=None, run_da
# group sub-task logs and write to trace file
random_filename = '{}.txt'.format(uuid.uuid4().hex)
with TemporaryFile() as tmp_file:
# Write Error logs
# Write Error logs
subtask_qs = analysis.sub_task_statuses.filter(
status__in=[AnalysisTaskStatus.status_choices.COMPLETED]
)
Expand Down Expand Up @@ -583,6 +583,7 @@ def record_sub_task_start(self, analysis_id=None, task_slug=None, task_id=None,
def record_sub_task_success(self, res, analysis_id=None, initiator_id=None, task_slug=None):
log_location = res.get('log_location')
error_location = res.get('error_location')
initiator = get_user_model().objects.get(pk=initiator_id)

task_id = self.request.parent_id
AnalysisTaskStatus.objects.filter(
Expand All @@ -592,17 +593,11 @@ def record_sub_task_success(self, res, analysis_id=None, initiator_id=None, task
task_id=task_id,
status=AnalysisTaskStatus.status_choices.COMPLETED,
end_time=timezone.now(),
output_log=None if not log_location else RelatedFile.objects.create(
file=str(log_location),
filename='{}-output.log'.format(task_id),
content_type='text/plain',
creator_id=initiator_id,
output_log=None if not log_location else store_file(
log_location, 'text/plain', initiator, filename=f'{task_id}-output.log'
),
error_log=None if not error_location else RelatedFile.objects.create(
file=str(error_location),
filename='{}-error.log'.format(task_id),
content_type='text/plain',
creator_id=initiator_id,
error_log=None if not error_location else store_file(
error_location, 'text/plain', initiator, filename=f'{task_id}-error.log'
)
)

Expand Down

0 comments on commit f9e9894

Please sign in to comment.