Skip to content

Commit

Permalink
Merge pull request #37 from kartoza/fix-worker-exceptions
Browse files Browse the repository at this point in the history
Fix worker logs + exceptions
  • Loading branch information
danangmassandy committed May 30, 2024
2 parents cf0b50b + 012976e commit 6e025b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django_project/cplus_api/api_views/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from django.shortcuts import get_object_or_404
from django.core.exceptions import ValidationError
from rest_framework.exceptions import ValidationError
from django.contrib.contenttypes.models import ContentType
from django.core.paginator import Paginator
from core.celery import cancel_task
Expand Down
16 changes: 15 additions & 1 deletion django_project/cplus_api/utils/worker_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ def __init__(self, task_config: TaskConfig,
self.scenario_task = scenario_task
self.last_update_progress = None
self.downloaded_layers = {}
self.downloaded_layer_count = 0

def prepare_run(self):
# clear existing scenario directory if exists
Expand All @@ -416,6 +417,8 @@ def prepare_run(self):
def initialize_input_layers(self, scenario_path: str):
self.log_message(
f'Initialize input layers: {self.task_config.total_input_layers}')
self.set_custom_progress(0)
self.set_status_message('Preparing input layers')

# init priority layers
priority_layer_paths = {}
Expand Down Expand Up @@ -522,6 +525,7 @@ def initialize_input_layers(self, scenario_path: str):
'Finished copy input layers: '
f'{self.task_config.total_input_layers}'
)
self.set_custom_progress(100)

def copy_input_layers_by_uuids(
self, component_type: InputLayer.ComponentTypes,
Expand All @@ -534,8 +538,19 @@ def copy_input_layers_by_uuids(
layers = layers.filter(
component_type=component_type
)
total_input_layers = (
self.task_config.total_input_layers if
self.task_config.total_input_layers > 0 else 1
)
for layer in layers:
file_path = layer.download_to_working_directory(scenario_path)
self.downloaded_layer_count += 1
self.set_custom_progress(
100 * (
self.downloaded_layer_count /
total_input_layers
)
)
if not file_path:
continue
if not os.path.exists(file_path):
Expand Down Expand Up @@ -771,7 +786,6 @@ def notify_user(self, is_success: bool):

def finished(self, result: bool):
if result:
self.log_message("Finished from the main task \n")
self.upload_scenario_outputs()
else:
self.log_message(
Expand Down

0 comments on commit 6e025b0

Please sign in to comment.