Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1777 | after_return to handle exception | a…
Browse files Browse the repository at this point in the history
…dded try catch in indexing
  • Loading branch information
snyaggarwal committed Mar 21, 2024
1 parent 39ac22c commit d36fcd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 10 additions & 6 deletions core/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
get_current_authorized_user
from core.common.utils import to_owner_uri
from core.settings import DEFAULT_LOCALE
from . import ERRBIT_LOGGER
from .checksums import ChecksumModel
from .constants import (
ACCESS_TYPE_CHOICES, DEFAULT_ACCESS_TYPE, NAMESPACE_REGEX,
Expand Down Expand Up @@ -182,12 +183,15 @@ def get_exact_or_criteria(attr, values):
@staticmethod
def batch_index(queryset, document, single_batch=False):
if not get(settings, 'TEST_MODE'):
doc = document()
if single_batch or not get(settings, 'DB_CURSOR_ON', True):
doc.update(queryset.all(), parallel=True)
else:
for batch in queryset.iterator(chunk_size=500):
doc.update(batch, parallel=True)
try:
doc = document()
if single_batch or not get(settings, 'DB_CURSOR_ON', True):
doc.update(queryset.all(), parallel=True)
else:
for batch in queryset.iterator(chunk_size=500):
doc.update(batch, parallel=True)
except Exception as e:
ERRBIT_LOGGER.log(e)

@staticmethod
@transaction.atomic
Expand Down
4 changes: 4 additions & 0 deletions core/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ def after_return(cls, status, retval, task_id, args, kwargs, einfo): # pylint:
task.state = status
task.result = retval
task.finished_at = timezone.now()
if isinstance(task.result, Exception):
task.result = str(task.result)
task.record_exception(task.result)

return task.save_common(args, kwargs, einfo)

@classmethod
Expand Down

0 comments on commit d36fcd5

Please sign in to comment.