def _check_complete(self, workitems): """End instance if only daemons are left. workitems -- list of active workitems (passed for performance reasons) This method is a bit weird, but works. There are two cases: 1. If no active work items are left, we complete the instance. 2. If only daemons are left, we complete those. As a side effect, when the last daemon is completed, we get another trigger for _check_complete and the instance will be completed by case 1. """ if self._creating: # Do not check for completeness while we are still creating work # items. return controller = ILifeCycleController(self) daemons = [ wi for wi in workitems if IDaemonActivity.providedBy(wi.getActivity()) ] items_active = len(workitems) daemons_active = len(daemons) if controller.state != "active": # XXX Missing test # We don't have to check further as we are not active. return if not items_active: # Case 1: No active work items controller.complete( "Automatically completed instance as all work items ended.") if (controller.state == "active" and items_active == daemons_active): # Case 2: Only daemons are active for daemon in daemons: ILifeCycleController(daemon).complete( "Automatically completed daemon.")
def _rememberTrigger(self, triggering_workitem, route): mode = self.getActivity().mode all_routes = self._getAllRoutes() closed_routes = self.closed_routes if route in closed_routes: return controller = ILifeCycleController(self) if mode == MULTI_MERGE: closed_routes.append(route) self._doTrigger(triggering_workitem, route) if len(closed_routes) == len(all_routes): self.completing_work_item = triggering_workitem # XXX no test for this controller.complete("Gate '%s' found by route '%s'" % (self.activity_id, route)) elif mode == DISCRIMINATE: if len(closed_routes) == 0: self._doTrigger(triggering_workitem, route) self.completing_work_item = triggering_workitem controller.complete("Gate '%s' found by route '%s'" % (self.activity_id, route)) closed_routes.append(route) elif mode == DELAYED_DISCRIMINATE: self.delayed_discriminator = True elif mode == SYNCHRONIZING_MERGE: closed_routes.append(route) if len(closed_routes) == len(all_routes): self._doTrigger(triggering_workitem, route) self.completing_work_item = triggering_workitem controller.complete("Gate '%s' completed via route '%s'" % (self.activity_id, route)) else: # XXX no tests for this controller.fail("Unknown gate mode: '%s'" % mode) self.closed_routes = closed_routes