Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #266 from pgdr/safe-check-queue-index
Browse files Browse the repository at this point in the history
Add safe check of queue index
  • Loading branch information
pgdr authored Mar 20, 2018
2 parents 376f8b0 + 950fa7e commit 7bec1eb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions libenkf/include/ert/enkf/run_arg.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ UTIL_IS_INSTANCE_HEADER( run_arg );
const char * run_arg_get_run_id( const run_arg_type * run_arg);
run_status_type run_arg_get_run_status( const run_arg_type * run_arg );

int run_arg_get_queue_index_safe( const run_arg_type * run_arg );
int run_arg_get_queue_index( const run_arg_type * run_arg );
bool run_arg_is_submitted( const run_arg_type * run_arg );

Expand Down
7 changes: 7 additions & 0 deletions libenkf/src/run_arg.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ run_mode_type run_arg_get_run_mode( const run_arg_type * run_arg ) {
}


int run_arg_get_queue_index_safe( const run_arg_type * run_arg ) {
if (run_arg->queue_index == INVALID_QUEUE_INDEX)
return -1;

return run_arg->queue_index;
}

int run_arg_get_queue_index( const run_arg_type * run_arg ) {
if (run_arg->queue_index == INVALID_QUEUE_INDEX)
util_abort("%s: sorry internal error - asking for the queue_index in a not-initialized run_arg object.\n" , __func__);
Expand Down
3 changes: 3 additions & 0 deletions libenkf/tests/enkf_run_arg.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ void test_queue_index() {
test_assert_false( run_arg_is_submitted( run_arg ) );
test_assert_util_abort("run_arg_get_queue_index" , call_get_queue_index , run_arg );

int qi = run_arg_get_queue_index_safe( run_arg );
test_assert_int_equal( -1, qi ); // not submitted: index == -1

run_arg_set_queue_index(run_arg, 78);
test_assert_true( run_arg_is_submitted( run_arg ) );
test_assert_int_equal( 78 , run_arg_get_queue_index( run_arg ));
Expand Down
7 changes: 5 additions & 2 deletions python/python/res/enkf/run_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RunArg(BaseCClass):

_alloc_ENSEMBLE_EXPERIMENT = EnkfPrototype("run_arg_obj run_arg_alloc_ENSEMBLE_EXPERIMENT(char*, enkf_fs, int, int, char*, char*, subst_list)", bind = False)
_free = EnkfPrototype("void run_arg_free(run_arg)")
_get_queue_index = EnkfPrototype("int run_arg_get_queue_index(run_arg)")
_get_queue_index_safe = EnkfPrototype("int run_arg_get_queue_index_safe(run_arg)")
_is_submitted = EnkfPrototype("bool run_arg_is_submitted(run_arg)")
_get_run_id = EnkfPrototype("char* run_arg_get_run_id(run_arg)")
_get_geo_id = EnkfPrototype("int run_arg_get_geo_id(run_arg)")
Expand All @@ -40,7 +40,10 @@ def free(self):
self._free()

def getQueueIndex(self):
return self._get_queue_index()
qi = self._get_queue_index_safe()
if qi < 0:
raise ValueError('Cannot get queue index before job is submitted.')
return qi

def isSubmitted(self):
return self._is_submitted()
Expand Down
11 changes: 9 additions & 2 deletions python/python/res/server/simulation_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ def job_progress(self, iens):
raise KeyError("No such simulation: %s" % iens)

run_arg = self._run_args[iens]
queue_index = run_arg.getQueueIndex()
try:
# will throw if not yet submitted (is in a limbo state)
queue_index = run_arg.getQueueIndex()
except ValueError:
return None
if self._queue_manager.isJobWaiting(queue_index):
return None

Expand All @@ -166,5 +170,8 @@ def job_status(self, iens):
raise KeyError("No such simulation: %s" % iens)

run_arg = self._run_args[iens]
queue_index = run_arg.getQueueIndex()
try:
queue_index = run_arg.getQueueIndex()
except ValueError:
return None
return self._queue_manager.getJobStatus(queue_index)
3 changes: 3 additions & 0 deletions python/tests/res/enkf/test_run_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def test_create(self):
run_id1 = run_context1.get_id( )

run_arg0 = run_context1[0]
with self.assertRaises(ValueError):
run_arg0.getQueueIndex()

self.assertEqual( run_id1 , run_arg0.get_run_id( ))

run_context2 = ErtRunContext( EnkfRunType.ENSEMBLE_EXPERIMENT , sim_fs , target_fs, mask , runpath_fmt, jobname_fmt, subst_list , itr )
Expand Down

0 comments on commit 7bec1eb

Please sign in to comment.