When saving JobEvents, include job_created

* this is the partition key
* .. used to determine which partition job event rows are sent to
This commit is contained in:
Jim Ladd 2021-02-10 20:23:44 -08:00
parent 2f737f644f
commit c0d38e91f5
2 changed files with 19 additions and 5 deletions

View File

@ -430,6 +430,11 @@ class BasePlaybookEvent(CreatedModifiedModel):
event = cls(**kwargs)
if workflow_job_id:
setattr(event, 'workflow_job_id', workflow_job_id)
# shouldn't job_created _always_ be present?
# if it's not, how could we save the event to the db?
job_created = kwargs.pop('job_created', None)
if job_created:
setattr(event, 'job_created', job_created)
setattr(event, 'host_map', host_map)
event._update_from_event_data()
return event
@ -444,7 +449,7 @@ class JobEvent(BasePlaybookEvent):
An event/message logged from the callback when running a job.
"""
VALID_KEYS = BasePlaybookEvent.VALID_KEYS + ['job_id', 'workflow_job_id']
VALID_KEYS = BasePlaybookEvent.VALID_KEYS + ['job_id', 'workflow_job_id', 'job_created']
class Meta:
app_label = 'main'
@ -567,7 +572,7 @@ class JobEvent(BasePlaybookEvent):
class ProjectUpdateEvent(BasePlaybookEvent):
VALID_KEYS = BasePlaybookEvent.VALID_KEYS + ['project_update_id', 'workflow_job_id']
VALID_KEYS = BasePlaybookEvent.VALID_KEYS + ['project_update_id', 'workflow_job_id', 'job_created']
class Meta:
app_label = 'main'
@ -685,7 +690,7 @@ class BaseCommandEvent(CreatedModifiedModel):
class AdHocCommandEvent(BaseCommandEvent):
VALID_KEYS = BaseCommandEvent.VALID_KEYS + ['ad_hoc_command_id', 'event', 'host_name', 'host_id', 'workflow_job_id']
VALID_KEYS = BaseCommandEvent.VALID_KEYS + ['ad_hoc_command_id', 'event', 'host_name', 'host_id', 'workflow_job_id', 'job_created']
class Meta:
app_label = 'main'
@ -774,7 +779,7 @@ class AdHocCommandEvent(BaseCommandEvent):
class InventoryUpdateEvent(BaseCommandEvent):
VALID_KEYS = BaseCommandEvent.VALID_KEYS + ['inventory_update_id', 'workflow_job_id']
VALID_KEYS = BaseCommandEvent.VALID_KEYS + ['inventory_update_id', 'workflow_job_id', 'job_created']
class Meta:
app_label = 'main'
@ -808,7 +813,7 @@ class InventoryUpdateEvent(BaseCommandEvent):
class SystemJobEvent(BaseCommandEvent):
VALID_KEYS = BaseCommandEvent.VALID_KEYS + ['system_job_id']
VALID_KEYS = BaseCommandEvent.VALID_KEYS + ['system_job_id', 'job_created']
class Meta:
app_label = 'main'

View File

@ -781,6 +781,7 @@ class BaseTask(object):
self.parent_workflow_job_id = None
self.host_map = {}
self.guid = GuidMiddleware.get_guid()
self.job_created = None
def update_model(self, pk, _attempt=0, **updates):
"""Reload the model instance from the database and update the
@ -1158,6 +1159,10 @@ class BaseTask(object):
event_data.pop('parent_uuid', None)
if self.parent_workflow_job_id:
event_data['workflow_job_id'] = self.parent_workflow_job_id
# Do we have to check if the field exists? if it doesn't
# how will be eventually store the event in the db?
if self.job_created:
event_data['job_created'] = self.job_created
if self.host_map:
host = event_data.get('event_data', {}).get('host', '').strip()
if host:
@ -1283,6 +1288,10 @@ class BaseTask(object):
if self.instance.spawned_by_workflow:
self.parent_workflow_job_id = self.instance.get_workflow_job().id
# TODO: can we count on instance always having created?
# If we can't how can we store the job_event?
self.job_created = self.instance.created
try:
self.instance.send_notification_templates("running")
private_data_dir = self.build_private_data_dir(self.instance)