Browse Source

Merge "Add more steps to stop an engine"

Jenkins 4 years ago
parent
commit
e9cb9ab547
1 changed files with 19 additions and 8 deletions
  1. 19
    8
      entropy/engine.py

+ 19
- 8
entropy/engine.py View File

@@ -128,7 +128,7 @@ class Engine(object):
128 128
         self._watchdog_thread.join()
129 129
 
130 130
     def schedule(self):
131
-        while True:
131
+        while self._state == self.ENABLED:
132 132
             (next_time, next_jobs) = self.wait_next(self.engine_timeout)
133 133
             # NOTE(praneshp): here, call a function that will wait till next
134 134
             # time and call next_jobs,
@@ -146,8 +146,8 @@ class Engine(object):
146 146
                 if not self.run_queue:
147 147
                     if watch and watch.expired():
148 148
                         raise exceptions.TimeoutException(
149
-                            "Died after waiting for audits to arrive for %s" %
150
-                            watch.elapsed())
149
+                            "Died at %s after waiting for audits to arrive "
150
+                            "for %s" % (utils.wallclock(), watch.elapsed()))
151 151
                 else:
152 152
                     # Grab all the jobs for the next time.
153 153
                     next_jobs.append(self.run_queue.popleft())
@@ -169,12 +169,13 @@ class Engine(object):
169 169
         now = datetime.datetime.now()
170 170
         cron = croniter.croniter(schedule, now)
171 171
         next_iteration = cron.get_next(datetime.datetime)
172
-        while True:
172
+        while self._state == self.ENABLED:
173 173
             LOG.info('It is %s, next serializer at %s', now, next_iteration)
174 174
             pause.until(next_iteration)
175 175
             now = datetime.datetime.now()
176 176
             next_iteration = cron.get_next(datetime.datetime)
177
-            self.run_serializer(next_iteration, now)
177
+            if self._state == self.ENABLED:
178
+                self.run_serializer(next_iteration, now)
178 179
 
179 180
     def run_serializer(self, next_iteration, current_time):
180 181
         LOG.info("Running serializer for %s at %s", self.name, current_time)
@@ -201,7 +202,10 @@ class Engine(object):
201 202
 
202 203
             new_additions.sort(key=operator.itemgetter('time'))
203 204
 
204
-            self.run_queue.extend(new_additions)
205
+            # NOTE(praneshp): Protect this operation with a state check, so in
206
+            # case of race conditions no extra audit scripts are added.
207
+            if self._state == self.ENABLED:
208
+                self.run_queue.extend(new_additions)
205 209
             LOG.info("Run queue till %s is %s", next_iteration, self.run_queue)
206 210
             LOG.info("Repair scripts at %s: %s", next_iteration, self._repairs)
207 211
         except Exception:
@@ -216,8 +220,10 @@ class Engine(object):
216 220
     def stop_engine(self):
217 221
         LOG.info("Stopping engine %s", self.name)
218 222
         # Set state to stop, which will stop serializers
219
-        LOG.info("Setting %s to state: %s", self.name, states.DISABLED)
220
-        self._state = states.DISABLED
223
+        # Clear run queue
224
+        LOG.info("Clearing audit run queue for %s", self.name)
225
+        self.run_queue.clear()
226
+        # Stop all repairs - not yet implemented
221 227
         # Stop watchdog monitoring
222 228
         LOG.info("Stopping watchdog for %s", self.name)
223 229
         self._watchdog_thread.stop()
@@ -236,6 +242,11 @@ class Engine(object):
236 242
     def setup_audit(self, execution_time, audit_list):
237 243
         try:
238 244
             pause.until(execution_time)
245
+            # Only proceed if engine is running, i.e in enabled state.
246
+            if self._state != self.ENABLED:
247
+                LOG.info("%s is disabled, so not running audits at %s",
248
+                         self.name, execution_time)
249
+                return
239 250
             LOG.info("Time: %s, Starting %s", execution_time, audit_list)
240 251
             audit_futures = []
241 252
             for audit in audit_list:

Loading…
Cancel
Save