intentionally forget start_args when job is done

This commit is contained in:
AlanCoding 2017-11-30 08:12:25 -05:00
parent 526bcc4a68
commit 1f8cab4171
No known key found for this signature in database
GPG Key ID: FD2C3C012A72926B
5 changed files with 9 additions and 6 deletions

View File

@ -1236,7 +1236,8 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
if not self.cancel_flag:
self.cancel_flag = True
cancel_fields = ['cancel_flag']
self.start_args = '' # blank field to remove encrypted passwords
cancel_fields = ['cancel_flag', 'start_args']
if self.status in ('pending', 'waiting', 'new'):
self.status = 'canceled'
cancel_fields.append('status')

View File

@ -479,6 +479,7 @@ class TaskManager():
if isolated:
new_status = 'error'
task.status = new_status
task.start_args = '' # blank field to remove encrypted passwords
if isolated:
# TODO: cancel and reap artifacts of lost jobs from heartbeat
task.job_explanation += ' '.join((
@ -493,7 +494,7 @@ class TaskManager():
'Celery, so it has been marked as failed.',
))
try:
task.save(update_fields=['status', 'job_explanation'])
task.save(update_fields=['status', 'start_args', 'job_explanation'])
except DatabaseError:
logger.error("Task {} DB error in marking failed. Job possibly deleted.".format(task.log_format))
continue

View File

@ -759,7 +759,8 @@ class BaseTask(LogErrorsTask):
execution_node = settings.CLUSTER_HOST_ID
if isolated_host is not None:
execution_node = isolated_host
instance = self.update_model(pk, status='running', execution_node=execution_node)
instance = self.update_model(pk, status='running', execution_node=execution_node,
start_args='') # blank field to remove encrypted passwords
instance.websocket_emit_status("running")
status, rc, tb = 'error', None, ''

View File

@ -52,7 +52,7 @@ def test_cancel(unified_job):
# Some more thought may want to go into only emitting canceled if/when the job record
# status is changed to canceled. Unlike, currently, where it's emitted unconditionally.
unified_job.websocket_emit_status.assert_called_with("canceled")
unified_job.save.assert_called_with(update_fields=['cancel_flag', 'status'])
unified_job.save.assert_called_with(update_fields=['cancel_flag', 'start_args', 'status'])
def test_cancel_job_explanation(unified_job):
@ -61,7 +61,7 @@ def test_cancel_job_explanation(unified_job):
unified_job.cancel(job_explanation=job_explanation)
assert unified_job.job_explanation == job_explanation
unified_job.save.assert_called_with(update_fields=['cancel_flag', 'status', 'job_explanation'])
unified_job.save.assert_called_with(update_fields=['cancel_flag', 'start_args', 'status', 'job_explanation'])
def test_log_representation():

View File

@ -271,7 +271,7 @@ class TestGenericRun(TestJobExecution):
with pytest.raises(Exception):
self.task.run(self.pk)
for c in [
mock.call(self.pk, execution_node=settings.CLUSTER_HOST_ID, status='running'),
mock.call(self.pk, execution_node=settings.CLUSTER_HOST_ID, status='running', start_args=''),
mock.call(self.pk, status='canceled')
]:
assert c in self.task.update_model.call_args_list