Skip to content

Commit

Permalink
Namechange events_processed -> event_processing_finished
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AlanCoding committed Mar 14, 2018
1 parent b803a6e commit 04a27d5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
10 changes: 5 additions & 5 deletions awx/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ def to_representation(self, obj):

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
Expand All @@ -696,7 +696,7 @@ class Meta:
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',
Expand Down Expand Up @@ -786,13 +786,13 @@ def to_representation(self, obj):
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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion awx/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def destroy(self, request, *args, **kwargs):
# 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
Expand Down
2 changes: 1 addition & 1 deletion awx/main/models/unified_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ def get_event_queryset(self):
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
'''
Expand Down
11 changes: 10 additions & 1 deletion awx/main/tests/unit/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

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



Expand Down Expand Up @@ -305,6 +305,15 @@ def test_cancel_flag(self):
]:
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:
Expand Down

0 comments on commit 04a27d5

Please sign in to comment.