Skip to content

Commit

Permalink
Merge pull request #309 from irontable/develop
Browse files Browse the repository at this point in the history
fix RunningJob().is_done bug with INIT status in Python client
  • Loading branch information
irontablee committed Jul 12, 2016
2 parents 13e260e + fafa24b commit b4e5801
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 4 deletions.
13 changes: 10 additions & 3 deletions genie-client/src/main/python/pygenie/jobs/running.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@

logger = logging.getLogger('com.netflix.genie.jobs.running')

RUNNING_STATUSES = {
'INIT',
'RUNNING',
'init',
'running'
}


def update_info(func):
"""
Expand All @@ -33,7 +40,7 @@ def wrapper(*args, **kwargs):

self = args[0]
status = self._info.get('status')
if status is None or status.upper() in {'INIT', 'RUNNING'}:
if status is None or status.upper() in RUNNING_STATUSES:
self.update()

return func(*args, **kwargs)
Expand Down Expand Up @@ -223,7 +230,7 @@ def is_done(self):
boolean: True if the job is done, False if still running.
"""

return self.status != 'RUNNING'
return self.status not in RUNNING_STATUSES

@property
def is_successful(self):
Expand Down Expand Up @@ -555,7 +562,7 @@ def wait(self, sleep_seconds=10, suppress_stream=False):

i = 0

while self._adapter.get_status(self._job_id).upper() in {'INIT', 'RUNNING'}:
while self._adapter.get_status(self._job_id).upper() in RUNNING_STATUSES:
if i % 3 == 0 and not suppress_stream:
self._write_to_stream('.')
time.sleep(sleep_seconds)
Expand Down
2 changes: 1 addition & 1 deletion genie-client/src/main/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

setup(
name='nflx-genie-client',
version='3.0.14',
version='3.0.15',
author='Netflix Inc.',
author_email='genieoss@googlegroups.com',
keywords='genie hadoop cloud netflix client bigdata presto',
Expand Down
86 changes: 86 additions & 0 deletions genie-client/src/main/python/tests/job_tests/test_runningjob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import unittest

from mock import patch
from nose.tools import assert_equals, assert_raises

import pygenie


assert_equals.__self__.maxDiff = None


@patch.dict('os.environ', {'GENIE_BYPASS_HOME_CONFIG': '1'})
class TestingRunningJobIsDone(unittest.TestCase):
"""Test RunningJob().is_done."""

@patch('pygenie.jobs.RunningJob.update')
def test_init_status(self, rj_update):
"""Test RunningJob().is_done with 'INIT' status."""

rj_update.side_effect = None

running_job = pygenie.jobs.RunningJob('1234-init',
info={'status': 'INIT'})

assert_equals(
running_job.is_done,
False
)

@patch('pygenie.jobs.RunningJob.update')
def test_running_status(self, rj_update):
"""Test RunningJob().is_done with 'RUNNING' status."""

rj_update.side_effect = None

running_job = pygenie.jobs.RunningJob('1234-running',
info={'status': 'RUNNING'})

assert_equals(
running_job.is_done,
False
)

@patch('pygenie.jobs.RunningJob.update')
def test_killed_status(self, rj_update):
"""Test RunningJob().is_done with 'KILLED' status."""

rj_update.side_effect = None

running_job = pygenie.jobs.RunningJob('1234-killed',
info={'status': 'KILLED'})

assert_equals(
running_job.is_done,
True
)

@patch('pygenie.jobs.RunningJob.update')
def test_succeeded_status(self, rj_update):
"""Test RunningJob().is_done with 'SUCCEEDED' status."""

rj_update.side_effect = None

running_job = pygenie.jobs.RunningJob('1234-succeeded',
info={'status': 'SUCCEEDED'})

assert_equals(
running_job.is_done,
True
)

@patch('pygenie.jobs.RunningJob.update')
def test_failed_status(self, rj_update):
"""Test RunningJob().is_done with 'FAILED' status."""

rj_update.side_effect = None

running_job = pygenie.jobs.RunningJob('1234-failed',
info={'status': 'FAILED'})

assert_equals(
running_job.is_done,
True
)

0 comments on commit b4e5801

Please sign in to comment.