Namechange events_processed -> event_processing_finished

from PR review, also adding tests to assert that the
value is passed from the stdout_handle to the UnifiedJob
object on finalization of job run in tasks.py
This commit is contained in:
AlanCoding 2018-03-13 15:46:35 -04:00
parent b803a6e557
commit 04a27d5b4d
No known key found for this signature in database
GPG Key ID: FD2C3C012A72926B
4 changed files with 17 additions and 8 deletions

View File

@ -685,7 +685,7 @@ class UnifiedJobTemplateSerializer(BaseSerializer):
class UnifiedJobSerializer(BaseSerializer):
show_capabilities = ['start', 'delete']
events_processed = serializers.BooleanField(
event_processing_finished = serializers.BooleanField(
help_text=_('Indicates whether all of the events generated by this '
'unified job have been saved to the database.'),
read_only=True
@ -696,7 +696,7 @@ class UnifiedJobSerializer(BaseSerializer):
fields = ('*', 'unified_job_template', 'launch_type', 'status',
'failed', 'started', 'finished', 'elapsed', 'job_args',
'job_cwd', 'job_env', 'job_explanation', 'execution_node',
'result_traceback', 'events_processed')
'result_traceback', 'event_processing_finished')
extra_kwargs = {
'unified_job_template': {
'source': 'unified_job_template_id',
@ -786,13 +786,13 @@ class UnifiedJobSerializer(BaseSerializer):
class UnifiedJobListSerializer(UnifiedJobSerializer):
class Meta:
fields = ('*', '-job_args', '-job_cwd', '-job_env', '-result_traceback', '-events_processed')
fields = ('*', '-job_args', '-job_cwd', '-job_env', '-result_traceback', '-event_processing_finished')
def get_field_names(self, declared_fields, info):
field_names = super(UnifiedJobListSerializer, self).get_field_names(declared_fields, info)
# Meta multiple inheritance and -field_name options don't seem to be
# taking effect above, so remove the undesired fields here.
return tuple(x for x in field_names if x not in ('job_args', 'job_cwd', 'job_env', 'result_traceback', 'events_processed'))
return tuple(x for x in field_names if x not in ('job_args', 'job_cwd', 'job_env', 'result_traceback', 'event_processing_finished'))
def get_types(self):
if type(self) is UnifiedJobListSerializer:
@ -3509,7 +3509,7 @@ class WorkflowJobSerializer(LabelsListMixin, UnifiedJobSerializer):
class Meta:
model = WorkflowJob
fields = ('*', 'workflow_job_template', 'extra_vars', 'allow_simultaneous',
'-execution_node', '-events_processed',)
'-execution_node', '-event_processing_finished',)
def get_related(self, obj):
res = super(WorkflowJobSerializer, self).get_related(obj)

View File

@ -145,7 +145,7 @@ class UnifiedJobDeletionMixin(object):
# Still allow deletion of new status, because these can be manually created
if obj.status in ACTIVE_STATES and obj.status != 'new':
raise PermissionDenied(detail=_("Cannot delete running job resource."))
elif not obj.events_processed:
elif not obj.event_processing_finished:
# Prohibit deletion if job events are still coming in
if obj.finished and now() < obj.finished + dateutil.relativedelta.relativedelta(minutes=1):
# less than 1 minute has passed since job finished and events are not in

View File

@ -924,7 +924,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
return self.event_class.objects.filter(**{self.event_parent_key: self.id})
@property
def events_processed(self):
def event_processing_finished(self):
'''
Returns True / False, whether all events from job have been saved
'''

View File

@ -35,7 +35,7 @@ from awx.main.models import (
from awx.main import tasks
from awx.main.queue import CallbackQueueDispatcher
from awx.main.utils import encrypt_field, encrypt_value
from awx.main.utils import encrypt_field, encrypt_value, OutputEventFilter
@ -305,6 +305,15 @@ class TestGenericRun(TestJobExecution):
]:
assert c in self.task.update_model.call_args_list
def test_event_count(self):
with mock.patch.object(self.task, 'get_stdout_handle') as mock_stdout:
handle = OutputEventFilter(lambda event_data: None)
handle._event_ct = 334
mock_stdout.return_value = handle
self.task.run(self.pk)
assert self.task.update_model.call_args[-1]['emitted_events'] == 334
def test_artifact_cleanup(self):
path = tempfile.NamedTemporaryFile(delete=False).name
try: