Skip to content

Commit

Permalink
Merge pull request #679 from oda-hub/better-handling-case-multiple-jo…
Browse files Browse the repository at this point in the history
…b_id-dir

Better handling case multiple job id dir
  • Loading branch information
burnout87 authored May 17, 2024
2 parents 7c8c5bd + 2e37c1e commit a01e05c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cdci_data_analysis/flask_app/dispatcher_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1610,9 +1610,13 @@ def get_existing_job_ID_path(self, wd):
alias_dir = None

elif len(dir_list) > 1:
sentry.capture_message('Found two non aliased identical job_id')
print(f'Found two non aliased identical job_id, dir_list: {dir_list}')
raise RuntimeError('Found two non aliased identical job_id')
sentry.capture_message(f'Found two non aliased identical job_id, dir_list: {dir_list}')
self.logger.warning(f'Found two non aliased identical job_id, dir_list: {dir_list}')

raise InternalError("We have encountered an internal error! "
"Our team is notified and is working on it. We are sorry! "
"When we find a solution we will try to reach you",
status_code=500)

else:
alias_dir = None
Expand Down
42 changes: 42 additions & 0 deletions tests/test_server_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,48 @@ def test_matrix_options_mode_empty_request(dispatcher_live_fixture_with_matrix_o
logger.info(jdata['config'])


@pytest.mark.not_safe_parallel
@pytest.mark.fast
def test_error_two_scratch_dir_same_job_id(dispatcher_live_fixture):
DispatcherJobState.remove_scratch_folders()
server = dispatcher_live_fixture
logger.info("constructed server: %s", server)

encoded_token = jwt.encode(default_token_payload, secret_key, algorithm='HS256')
# issuing a request each, with the same set of parameters
params = dict(
query_status="new",
query_type="Real",
instrument="empty-async",
product_type="dummy",
token=encoded_token
)
DataServerQuery.set_status('submitted')
# let's generate a fake scratch dir
jdata = ask(server,
params,
expected_query_status=["submitted"],
max_time_s=50,
)

job_id = jdata['job_monitor']['job_id']
session_id = jdata['session_id']
fake_scratch_dir = f'scratch_sid_01234567890_jid_{job_id}'
os.makedirs(fake_scratch_dir)

params['job_id'] = job_id
params['session_id'] = session_id

jdata = ask(server,
params,
expected_status_code=500,
expected_query_status=None,
)
assert jdata['error'] == 'InternalError():We have encountered an internal error! Our team is notified and is working on it. We are sorry! When we find a solution we will try to reach you'
assert jdata['error_message'] == 'We have encountered an internal error! Our team is notified and is working on it. We are sorry! When we find a solution we will try to reach you'
os.rmdir(fake_scratch_dir)


@pytest.mark.fast
def test_same_request_different_users(dispatcher_live_fixture):
server = dispatcher_live_fixture
Expand Down

0 comments on commit a01e05c

Please sign in to comment.