Skip to content

Commit

Permalink
created a central utility function, added logic to determine timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
shayanaijaz committed Aug 30, 2023
1 parent 8a39f95 commit d9f665e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 18 deletions.
9 changes: 2 additions & 7 deletions server/portal/apps/webhooks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
validate_webhook,
execute_callback
)
from portal.apps.workspace.api.utils import check_job_for_timeout

from django.conf import settings

Expand Down Expand Up @@ -54,13 +55,7 @@ def validate_tapis_job(job_uuid, job_owner, disallowed_states=[]):
if job_data.status in disallowed_states:
return None

if hasattr(job_data, 'notes') and job_data.status == 'FAILED':
notes = json.loads(job_data.notes)

# checks to see if an interactive job ended with tapis timeout code of 0:0
if notes.get('isInteractive', False) and job_data.remoteResultInfo == '0:0':
job_data.status = 'FINISHED'
job_data.remoteOutcome = 'FINISHED'
job_data = check_job_for_timeout(job_data)

return job_data

Expand Down
23 changes: 23 additions & 0 deletions server/portal/apps/workspace/api/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json


def get_tapis_timeout_error_messages(job_id):
return [
'JOBS_EARLY_TERMINATION Job terminated by Tapis because: TIME_EXPIRED',
f'JOBS_USER_APP_FAILURE The user application ({job_id}) ended with remote status "TIMEOUT" and returned exit code: 0:0.'
]


def check_job_for_timeout(job):
if (hasattr(job, 'notes')):
notes = json.loads(job.notes)

is_failed = job.status == 'FAILED'
is_interactive = notes.get('isInteractive', False)
has_timeout_message = job.lastMessage in get_tapis_timeout_error_messages(job.remoteJobId)

if is_failed and is_interactive and has_timeout_message:
job.status = 'FINISHED'
job.remoteOutcome = 'FINISHED'

return job
33 changes: 22 additions & 11 deletions server/portal/apps/workspace/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from portal.apps.onboarding.steps.system_access_v3 import create_system_credentials
from portal.apps.users.utils import get_user_data
from .handlers.tapis_handlers import tapis_get_handler
from portal.apps.workspace.api.utils import check_job_for_timeout

logger = logging.getLogger(__name__)
METRICS = logging.getLogger('metrics.{}'.format(__name__))
Expand Down Expand Up @@ -139,17 +140,27 @@ def get(self, request, *args, **kwargs):
@method_decorator(login_required, name='dispatch')
class JobsView(BaseApiView):

@staticmethod
def check_job_for_timeout(job):
if hasattr(job, 'notes') and job.status == 'FAILED':
notes = json.loads(job.notes)
# @staticmethod
# def get_tapis_timeout_error_messages(job_id):
# return [
# 'JOBS_EARLY_TERMINATION Job terminated by Tapis because: TIME_EXPIRED',
# f'JOBS_USER_APP_FAILURE The user application ({job_id}) ended with remote status "TIMEOUT" and returned exit code: 0:0.'
# ]

# checks to see if an interactive job ended with tapis timeout code of 0:0
if notes.get('isInteractive', False) and job.remoteResultInfo == '0:0':
job.status = 'FINISHED'
job.remoteOutcome = 'FINISHED'
# @staticmethod
# def check_job_for_timeout(job, timeout_messages):
# if (hasattr(job, 'notes')):
# notes = json.loads(job.notes)

return job
# is_failed = job.status == 'FAILED'
# is_interactive = notes.get('isInteractive', False)
# has_timeout_message = job.lastMessage in timeout_messages

# if is_failed and is_interactive and has_timeout_message:
# job.status = 'FINISHED'
# job.remoteOutcome = 'FINISHED'

# return job

def get(self, request, operation=None):

Expand All @@ -165,9 +176,9 @@ def get(self, request, operation=None):

if (isinstance(data, list)):
for index, job in enumerate(data):
data[index] = self.check_job_for_timeout(job)
data[index] = check_job_for_timeout(job)
else:
data = self.check_job_for_timeout(data)
data = check_job_for_timeout(data)

return JsonResponse(
{
Expand Down

0 comments on commit d9f665e

Please sign in to comment.