|
1 | 1 | import json
|
| 2 | +import os.path |
2 | 3 | import time
|
3 | 4 | import logging
|
4 | 5 | from collections import deque
|
5 | 6 |
|
6 | 7 | # Django
|
7 | 8 | from django.conf import settings
|
| 9 | +from django.contrib.messages.api import error |
8 | 10 | from django_guid import get_guid
|
9 | 11 | from django.utils.functional import cached_property
|
10 | 12 | from django.db import connections
|
|
15 | 17 | from awx.main.utils.update_model import update_model
|
16 | 18 | from awx.main.queue import CallbackQueueDispatcher
|
17 | 19 |
|
| 20 | +from flags.state import flag_enabled |
| 21 | + |
18 | 22 | logger = logging.getLogger('awx.main.tasks.callback')
|
19 | 23 |
|
20 | 24 |
|
| 25 | +def try_load_query_file(artifact_dir) -> (bool, dict): |
| 26 | + if not flag_enabled("FEATURE_INDIRECT_NODE_COUNTING_ENABLED"): |
| 27 | + return False, None |
| 28 | + |
| 29 | + queries_path = os.path.join(artifact_dir, "ansible_data.json") |
| 30 | + if not os.path.isfile(queries_path): |
| 31 | + logger.info(f"no query file found: {queries_path}") |
| 32 | + return False, None |
| 33 | + |
| 34 | + try: |
| 35 | + f = open(queries_path, "r") |
| 36 | + except OSError as e: |
| 37 | + logger.error(f"error opening query file {queries_path}: {e}") |
| 38 | + return False, None |
| 39 | + |
| 40 | + with f: |
| 41 | + try: |
| 42 | + queries = json.load(f) |
| 43 | + except ValueError as e: |
| 44 | + logger.error(f"error parsing query file {queries_path}: {e}") |
| 45 | + return False, None |
| 46 | + |
| 47 | + return True, queries |
| 48 | + |
| 49 | + |
21 | 50 | class RunnerCallback:
|
22 | 51 | def __init__(self, model=None):
|
| 52 | + self.instance = None |
23 | 53 | self.parent_workflow_job_id = None
|
24 | 54 | self.host_map = {}
|
25 | 55 | self.guid = get_guid()
|
@@ -214,6 +244,10 @@ def status_handler(self, status_data, runner_config):
|
214 | 244 | self.delay_update(**{field_name: field_value})
|
215 | 245 |
|
216 | 246 | def artifacts_handler(self, artifact_dir):
|
| 247 | + success, query_file_contents = try_load_query_file(artifact_dir) |
| 248 | + if success: |
| 249 | + self.instance = self.update_model(self.instance.pk, job_queries=query_file_contents) |
| 250 | + |
217 | 251 | self.artifacts_processed = True
|
218 | 252 |
|
219 | 253 |
|
|
0 commit comments