Browse Source

Read old json data right before writing new data

Instead of holding the old log data in RAM for the entire run, just read
it in right before writing the new data out.

Change-Id: I9785475b8c876f2cf8e61c5926e6c9d43a432deb
tags/3.4.0
Monty Taylor 5 months ago
parent
commit
43a03ef19f
No account linked to committer's email address
1 changed files with 9 additions and 8 deletions
  1. 9
    8
      zuul/ansible/callback/zuul_json.py

+ 9
- 8
zuul/ansible/callback/zuul_json.py View File

@@ -55,7 +55,6 @@ class CallbackModule(CallbackBase):
55 55
     def __init__(self, display=None):
56 56
         super(CallbackModule, self).__init__(display)
57 57
         self.results = []
58
-        self.output = []
59 58
         self.playbook = {}
60 59
         logging_config = logconfig.load_job_config(
61 60
             os.environ['ZUUL_JOB_LOG_CONFIG'])
@@ -63,11 +62,6 @@ class CallbackModule(CallbackBase):
63 62
         self.output_path = os.path.splitext(
64 63
             logging_config.job_output_file)[0] + '.json'
65 64
 
66
-        # For now, just read in the old file and write it all out again
67
-        # This may well not scale from a memory perspective- but let's see how
68
-        # it goes.
69
-        if os.path.exists(self.output_path):
70
-            self.output = json.load(open(self.output_path, 'r'))
71 65
         self._playbook_name = None
72 66
 
73 67
     def _new_playbook(self, play):
@@ -173,9 +167,16 @@ class CallbackModule(CallbackBase):
173 167
 
174 168
         self.playbook['plays'] = self.results
175 169
         self.playbook['stats'] = summary
176
-        self.output.append(self.playbook)
177 170
 
178
-        json.dump(self.output, open(self.output_path, 'w'),
171
+        # For now, just read in the old file and write it all out again
172
+        # This may well not scale from a memory perspective- but let's see how
173
+        # it goes.
174
+        output = []
175
+        if os.path.exists(self.output_path):
176
+            output = json.load(open(self.output_path, 'r'))
177
+        output.append(self.playbook)
178
+
179
+        json.dump(output, open(self.output_path, 'w'),
179 180
                   indent=4, sort_keys=True, separators=(',', ': '))
180 181
 
181 182
     v2_runner_on_failed = v2_runner_on_ok

Loading…
Cancel
Save