Skip to content

Commit

Permalink
Merge branch 'main' into task/wp-209-fix-deprecated-warnings-II
Browse files Browse the repository at this point in the history
  • Loading branch information
shayanaijaz authored Sep 8, 2023
2 parents 1fc16f5 + 7920857 commit a80eab9
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 26 deletions.
12 changes: 2 additions & 10 deletions client/src/components/_common/Button/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Icon from '../Icon';

import styles from './Button.module.css';
import LoadingSpinner from '_common/LoadingSpinner';
import emptyStringValidator from '_common/CommonUtils';

export const TYPE_MAP = {
primary: 'primary',
Expand All @@ -25,15 +26,6 @@ export const SIZES = [''].concat(Object.keys(SIZE_MAP));

export const ATTRIBUTES = ['button', 'submit', 'reset'];

function isNotEmptyString(props, propName, componentName) {
if (!props[propName] || props[propName].replace(/ /g, '') === '') {
return new Error(
`No text passed to <${componentName}> prop "${propName}". Validation failed.`
);
}
return null;
}

const Button = ({
children,
className,
Expand Down Expand Up @@ -125,7 +117,7 @@ const Button = ({
);
};
Button.propTypes = {
children: isNotEmptyString,
children: emptyStringValidator,
className: PropTypes.string,
iconNameBefore: PropTypes.string,
iconNameAfter: PropTypes.string,
Expand Down
19 changes: 19 additions & 0 deletions client/src/components/_common/CommonUtils.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Checks that the field is a non-empty string
* @param {Object} props -
* @param {String} propName - name of the property
* @param {String} componentName - name of the component
* @returns {String} Message if error, otherwise null
*/

export default function emptyStringValidator(props, propName, componentName) {
if (
!props[propName] ||
typeof props[propName] !== 'string' ||
props[propName].replace(/ /g, '') === ''
) {
return new Error(
`No text passed to <${componentName}> prop "${propName}". Validation failed.`
);
}
}
10 changes: 2 additions & 8 deletions client/src/components/_common/Sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ import { NavLink as RRNavLink } from 'react-router-dom';
import { Nav, NavItem, NavLink } from 'reactstrap';
import Icon from '_common/Icon';
import styles from './Sidebar.module.css';

function isNotEmptyString(props, propName, componentName) {
if (!props[propName] || props[propName].replace(/ /g, '') === '') {
return new Error(`No text passed to ${componentName}. Validation failed.`);
}
return null;
}
import emptyStringValidator from '_common/CommonUtils';

const SidebarItem = ({ to, iconName, label, children, disabled, hidden }) => {
return (
Expand Down Expand Up @@ -38,7 +32,7 @@ const SidebarItem = ({ to, iconName, label, children, disabled, hidden }) => {
SidebarItem.propTypes = {
to: PropTypes.string.isRequired,
iconName: PropTypes.string.isRequired,
label: isNotEmptyString,
label: emptyStringValidator,
children: PropTypes.node,
disabled: PropTypes.bool,
hidden: PropTypes.bool,
Expand Down
18 changes: 11 additions & 7 deletions server/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 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,6 +55,8 @@ def validate_tapis_job(job_uuid, job_owner, disallowed_states=[]):
if job_data.status in disallowed_states:
return None

job_data = check_job_for_timeout(job_data)

return job_data


Expand Down Expand Up @@ -122,6 +125,7 @@ def post(self, request, *args, **kwargs):
job_details = validate_tapis_job(job_uuid, username, disallowed_states=non_terminal_states)
if job_details:
event_data[Notification.EXTRA]['remoteOutcome'] = job_details.remoteOutcome
event_data[Notification.EXTRA]['status'] = job_details.status

try:
logger.info('Indexing job output for job={}'.format(job_uuid))
Expand Down
28 changes: 28 additions & 0 deletions server/portal/apps/workspace/api/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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):
"""
Check an interactive job for timeout status and mark it as finished
since Tapis does not have native support for interactive jobs yet
"""

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
8 changes: 8 additions & 0 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 @@ -138,6 +139,7 @@ def get(self, request, *args, **kwargs):

@method_decorator(login_required, name='dispatch')
class JobsView(BaseApiView):

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

allowed_actions = ['listing', 'search', 'select']
Expand All @@ -150,6 +152,12 @@ def get(self, request, operation=None):
op = getattr(self, operation)
data = op(tapis, request)

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

return JsonResponse(
{
'status': 200,
Expand Down
2 changes: 1 addition & 1 deletion server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cached-property = "^1.5.1"
ipython = "^8.13.2"
pycryptodome = "^3.9.7"
elasticsearch = "^7.7.1"
uwsgi = "^2.0.18"
uwsgi = "^2.0.22"
requests = "^2.31.0"
django-impersonate = "^1.5"
channels = "^2.4.0"
Expand Down

0 comments on commit a80eab9

Please sign in to comment.