def __init__(self, name, _addServices=True): service.MultiService.__init__(self) self.name = name # this is filled on demand by getBuilderId; don't access it directly self._builderid = None # build/wannabuild slots: Build objects move along this sequence self.building = [] # old_building holds active builds that were stolen from a predecessor self.old_building = weakref.WeakKeyDictionary() # workers which have connected but which are not yet available. # These are always in the ATTACHING state. self.attaching_workers = [] self._registerOldWorkerAttr("attaching_workers") # workers at our disposal. Each WorkerForBuilder instance has a # .state that is IDLE, PINGING, or BUILDING. "PINGING" is used when a # Build is about to start, to make sure that they're still alive. self.workers = [] self._registerOldWorkerAttr("workers") self.config = None self.builder_status = None if _addServices: self.reclaim_svc = internet.TimerService(10 * 60, self.reclaimAllBuilds) self.reclaim_svc.setServiceParent(self) # update big status every 30 minutes, working around #1980 self.updateStatusService = internet.TimerService( 30 * 60, self.updateBigStatus) self.updateStatusService.setServiceParent(self)
def __init__(self, name, _addServices=True): service.MultiService.__init__(self) self.name = name # this is created the first time we get a good build self.expectations = None # build/wannabuild slots: Build objects move along this sequence self.building = [] # old_building holds active builds that were stolen from a predecessor self.old_building = weakref.WeakKeyDictionary() # buildslaves which have connected but which are not yet available. # These are always in the ATTACHING state. self.attaching_slaves = [] # buildslaves at our disposal. Each SlaveBuilder instance has a # .state that is IDLE, PINGING, or BUILDING. "PINGING" is used when a # Build is about to start, to make sure that they're still alive. self.slaves = [] self.config = None self.builder_status = None if _addServices: self.reclaim_svc = internet.TimerService(10*60, self.reclaimAllBuilds) self.reclaim_svc.setServiceParent(self) # update big status every 30 minutes, working around #1980 self.updateStatusService = internet.TimerService(30*60, self.updateBigStatus) self.updateStatusService.setServiceParent(self)
def createQueue(port=8787, name=None, app=None, consumers=[], timerStep=1000, withRss=False, rssPort=6666): assert name is not None assert app is not None assert len(consumers) > 0 queueModel = __getQueue(name) scheduler = JobScheduler(queueModel) for chost, cport in consumers: scheduler.addConsumer(TwistedJobConsumer(chost, cport)) queue = internet.TCPServer(port, QueueFactory(scheduler)) queue.setServiceParent(app) timer = internet.TimerService(timerStep, scheduler.dispatchPending) timer.setServiceParent(app) if (withRss): site = server.Site(ErrorRssResource()) rss = strports.service('tcp:%s' % str(rssPort), channel.HTTPFactory(site)) rss.setServiceParent(app)
def server_service(port): """ Create Twisted service for OSC server ('receiver'). Callbacks for inbound messages must be registered here. """ return internet.TimerService(4, got_loop)
def testTimerRestart(self): # restart the same TimerService d1 = defer.Deferred() d2 = defer.Deferred() work = [(d2, "bar"), (d1, "foo")] def trigger(): d, arg = work.pop() d.callback(arg) self.t = internet.TimerService(1, trigger) self.t.startService() def onFirstResult(result): self.assertEqual(result, 'foo') return self.t.stopService() def onFirstStop(ignored): self.failIf(self.t.running) self.t.startService() return d2 def onSecondResult(result): self.assertEqual(result, 'bar') self.t.stopService() d1.addCallback(onFirstResult) d1.addCallback(onFirstStop) d1.addCallback(onSecondResult) return d1
def __init__(self, master, basedir): service.MultiService.__init__(self) self.setName('db') self.master = master self.basedir = basedir # not configured yet - we don't build an engine until the first # reconfig self.configured_url = None # set up components self._engine = None # set up in reconfigService self.pool = None # set up in reconfigService self.model = model.Model(self) self.changes = changes.ChangesConnectorComponent(self) self.schedulers = schedulers.SchedulersConnectorComponent(self) self.sourcestamps = sourcestamps.SourceStampsConnectorComponent(self) self.sourcestampsets = sourcestampsets.SourceStampSetsConnectorComponent( self) self.buildsets = buildsets.BuildsetsConnectorComponent(self) self.buildrequests = buildrequests.BuildRequestsConnectorComponent( self) self.state = state.StateConnectorComponent(self) self.builds = builds.BuildsConnectorComponent(self) self.users = users.UsersConnectorComponent(self) self.cleanup_timer = internet.TimerService(self.CLEANUP_PERIOD, self._doCleanup) self.cleanup_timer.setServiceParent(self)
def __init__(self, master, db_url, basedir): service.MultiService.__init__(self) self.master = master self.basedir = basedir self._engine = enginestrategy.create_engine(db_url, basedir=self.basedir) self.pool = pool.DBThreadPool(self._engine) # set up components self.model = model.Model(self) self.changes = changes.ChangesConnectorComponent(self) self.schedulers = schedulers.SchedulersConnectorComponent(self) self.sourcestamps = sourcestamps.SourceStampsConnectorComponent(self) self.buildsets = buildsets.BuildsetsConnectorComponent(self) self.buildrequests = buildrequests.BuildRequestsConnectorComponent( self) self.state = state.StateConnectorComponent(self) self.builds = builds.BuildsConnectorComponent(self) self.cleanup_timer = internet.TimerService(self.CLEANUP_PERIOD, self.doCleanup) self.cleanup_timer.setServiceParent(self) self.changeHorizon = None # default value; set by master
def __init__(self, relayport, transitport, advertise_version): service.MultiService.__init__(self) self.db = get_db("relay.sqlite") welcome = { "current_version": __version__, # adding .motd will cause all clients to display the message, # then keep running normally #"motd": "Welcome to the public relay.\nPlease enjoy this service.", # # adding .error will cause all clients to fail, with this message #"error": "This server has been disabled, see URL for details.", } if advertise_version: welcome["current_version"] = advertise_version self.root = Root() site = server.Site(self.root) self.relayport_service = strports.service(relayport, site) self.relayport_service.setServiceParent(self) self.relay = Relay(self.db, welcome) # accessible from tests self.root.putChild("wormhole-relay", self.relay) t = internet.TimerService(EXPIRATION_CHECK_PERIOD, self.relay.prune_old_channels) t.setServiceParent(self) if transitport: self.transit = Transit() self.transit.setServiceParent(self) # for the timer self.transport_service = strports.service(transitport, self.transit) self.transport_service.setServiceParent(self)
def setServiceParent(self, p): yield super().setServiceParent(p) self.model = model.Model(self) self.changes = changes.ChangesConnectorComponent(self) self.changesources = changesources.ChangeSourcesConnectorComponent( self) self.schedulers = schedulers.SchedulersConnectorComponent(self) self.sourcestamps = sourcestamps.SourceStampsConnectorComponent(self) self.buildsets = buildsets.BuildsetsConnectorComponent(self) self.buildrequests = buildrequests.BuildRequestsConnectorComponent( self) self.state = state.StateConnectorComponent(self) self.builds = builds.BuildsConnectorComponent(self) self.workers = workers.WorkersConnectorComponent(self) self.users = users.UsersConnectorComponent(self) self.masters = masters.MastersConnectorComponent(self) self.builders = builders.BuildersConnectorComponent(self) self.steps = steps.StepsConnectorComponent(self) self.tags = tags.TagsConnectorComponent(self) self.logs = logs.LogsConnectorComponent(self) self.cleanup_timer = internet.TimerService(self.CLEANUP_PERIOD, self._doCleanup) self.cleanup_timer.clock = self.master.reactor yield self.cleanup_timer.setServiceParent(self)
def create_child_services(self): # note that these are order-dependent. If you get the order wrong, # you'll know it, as the master will fail to start. self.metrics = metrics.MetricLogObserver() self.metrics.setServiceParent(self) self.caches = cache.CacheManager() self.caches.setServiceParent(self) self.pbmanager = buildbot.pbmanager.PBManager() self.pbmanager.setServiceParent(self) self.buildslaves = bslavemanager.BuildslaveManager(self) self.buildslaves.setServiceParent(self) self.change_svc = ChangeManager(self) self.change_svc.setServiceParent(self) self.botmaster = BotMaster(self) self.botmaster.setServiceParent(self) self.scheduler_manager = SchedulerManager(self) self.scheduler_manager.setServiceParent(self) self.user_manager = UserManagerManager(self) self.user_manager.setServiceParent(self) self.db = dbconnector.DBConnector(self, self.basedir) self.db.setServiceParent(self) self.mq = mqconnector.MQConnector(self) self.mq.setServiceParent(self) self.data = dataconnector.DataConnector(self) self.data.setServiceParent(self) self.www = wwwservice.WWWService(self) self.www.setServiceParent(self) self.debug = debug.DebugServices(self) self.debug.setServiceParent(self) self.status = Status(self) self.status.setServiceParent(self) self.masterHouskeepingTimer = 0 @defer.inlineCallbacks def heartbeat(): if self.masterid is not None: yield self.data.updates.masterActive(name=self.name, masterid=self.masterid) # force housekeeping once a day yield self.data.updates.expireMasters( (self.masterHouskeepingTimer % (24 * 60)) == 0) self.masterHouskeepingTimer += 1 self.masterHeartbeatService = internet.TimerService(60, heartbeat) self.masterHeartbeatService.setServiceParent(self)
def __init__(self, db, web, baseurl, desc): BaseServer.__init__(self) self.db = db assert baseurl.endswith("/") self.baseurl = baseurl self.transport_privkey = PrivateKey( desc["transport_privkey"].decode("hex")) self.TT_privkey = desc["TT_private_key"].decode("hex") self.TT_pubkey = desc["TT_public_key"].decode("hex") self.retrieval_privkey = PrivateKey( desc["retrieval_privkey"].decode("hex")) # this is how we get messages from senders web.get_root().putChild("mailbox", ServerResource(self.handle_msgA)) # add a second resource for agents to retrieve messages r = resource.Resource() # TODO: retrieval should use a different key than delivery self.listres = RetrievalListResource(self.db, self.retrieval_privkey) r.putChild("list", self.listres) ts = internet.TimerService(self.listres.CLOCK_WINDOW * 3, self.prune_old_requests) ts.setServiceParent(self) r.putChild("fetch", RetrievalFetchResource(self.db)) r.putChild("delete", RetrievalDeleteResource(self.db)) web.get_root().putChild("retrieval", r)
def setServiceParent(self, p): d = service.AsyncMultiService.setServiceParent(self, p) self.model = model.Model(self) self.changes = changes.ChangesConnectorComponent(self) self.changesources = changesources.ChangeSourcesConnectorComponent( self) self.schedulers = schedulers.SchedulersConnectorComponent(self) self.sourcestamps = sourcestamps.SourceStampsConnectorComponent(self) self.buildsets = buildsets.BuildsetsConnectorComponent(self) self.buildrequests = buildrequests.BuildRequestsConnectorComponent( self) self.state = state.StateConnectorComponent(self) self.builds = builds.BuildsConnectorComponent(self) self.workers = workers.WorkersConnectorComponent(self) self._registerOldWorkerAttr("workers", name="buildslaves") self.users = users.UsersConnectorComponent(self) self.masters = masters.MastersConnectorComponent(self) self.builders = builders.BuildersConnectorComponent(self) self.steps = steps.StepsConnectorComponent(self) self.tags = tags.TagsConnectorComponent(self) self.logs = logs.LogsConnectorComponent(self) self.cleanup_timer = internet.TimerService(self.CLEANUP_PERIOD, self._doCleanup) self.cleanup_timer.clock = self.master.reactor self.cleanup_timer.setServiceParent(self) return d
def __init__(self, descriptor, got_msgC): service.MultiService.__init__(self) self.descriptor = descriptor self.got_msgC = got_msgC self.ts = internet.TimerService(10 * 60, self.poll) if ENABLE_POLLING: self.ts.setServiceParent(self)
def testTimerRuns(self): d = defer.Deferred() self.t = internet.TimerService(1, d.callback, 'hello') self.t.startService() d.addCallback(self.assertEqual, 'hello') d.addCallback(lambda x: self.t.stopService()) d.addCallback(lambda x: self.failIf(self.t.running)) return d
def testBrokenTimer(self): t = internet.TimerService(1, lambda: 1 / 0) t.startService() util.spinWhile(lambda: t._loop.running, timeout=30) t.stopService() self.assertEquals( [ZeroDivisionError], [o.value.__class__ for o in log.flushErrors(ZeroDivisionError)])
def handle_in_create(self, path): if path not in self.timers: logger.info('path add to timers %s' % (path, )) frag = FlvFragment(path) self._shared_dict[get_channel(path)] = frag timer = internet.TimerService(config.TIMER_INTERVAL, self.watch, frag) self.timers[path] = timer timer.startService()
def testPickledTimer(self): target = TimerTarget() t0 = internet.TimerService(1, target.append, "hello") t0.startService() s = pickle.dumps(t0) t0.stopService() t = pickle.loads(s) self.failIf(t.running)
def __init__(self, basedir, pollinterval=1 * HOUR, old=1 * HOUR): service.MultiService.__init__(self) self.basedir = basedir fileutil.make_dirs(basedir) self.old = old self.files = weakref.WeakValueDictionary() t = internet.TimerService(pollinterval, self.check) t.setServiceParent(self)
def __init__(self, db, welcome): resource.Resource.__init__(self) service.MultiService.__init__(self) self.db = db self.welcome = welcome self.channels = {} t = internet.TimerService(EXPIRATION_CHECK_PERIOD, self.prune_old_channels) t.setServiceParent(self)
def postApplication(self): """ Start the application and run the reactor. """ service.IService(self.application).privilegedStartService() app.startApplication(self.application, not self.config['no_save']) app.startApplication(internet.TimerService(0.1, lambda:None), 0) self.startReactor(None, self.oldstdout, self.oldstderr) log.msg("Server Shut Down.")
def makeService(self, options): if not os.path.exists(options['conf']): raise OSError("Config File %s not found" % options['conf']) ms = MultiService() for step, callback in build_timers(options['timers']): svr = internet.TimerService(step, callback, options) svr.setServiceParent(ms) return ms
def subscribe(self, channelID): assert VALID_INVITEID.search(channelID), channelID self.verfkeys[channelID] = VerifyKey(channelID.decode("hex")) sdir = os.path.join(self.basedir, channelID) if not os.path.isdir(sdir): os.mkdir(sdir) self.subscriptions[channelID] = set() if len(self.subscriptions) == 1 and self.enable_polling: self.ts = internet.TimerService(01.1, self.poll) self.ts.setServiceParent(self)
def setUpCleanUp(self): cleanUpPeriod = self.master.config.cleanUpPeriod if cleanUpPeriod and cleanUpPeriod > 0: pruneBuildRequests = self.pool.engine.dialect.name == 'mysql' self.cleanup_timer = internet.TimerService( cleanUpPeriod, self._doCleanup, pruneBuildRequests) self.cleanup_timer.setServiceParent(self)
def __init__(self, name, builderNames, periodicBuildTimer, branch=None): BaseUpstreamScheduler.__init__(self, name) self.builderNames = builderNames self.periodicBuildTimer = periodicBuildTimer self.branch = branch self.reason = ( "The Periodic scheduler named '%s' triggered this build" % name) self.timer = internet.TimerService(self.periodicBuildTimer, self.doPeriodicBuild) self.timer.setServiceParent(self)
def __init__(self, db, welcome, blur_usage): service.MultiService.__init__(self) self._db = db self._welcome = welcome self._blur_usage = blur_usage log_requests = blur_usage is None self._log_requests = log_requests self._apps = {} t = internet.TimerService(EXPIRATION_CHECK_PERIOD, self.prune) t.setServiceParent(self)
def setupConfigChecker(configuration, director): """ This is the setup for the "config check" management task. """ checkInterval = configuration.manager.configCheckInterval checkerService = internet.TimerService(checkInterval, checker.checkConfigChanges, configuration, director) checkerService.setName('configChecker') return checkerService
def makeService(self): application = service.Application('Broadcaster') root = service.MultiService() root.setServiceParent(application) proto = PingPongProtocol(controller=self, port=8555) root.addService(internet.UDPServer(8555, proto)) root.addService(internet.TimerService(1, self.ping, proto)) return application
def makeService(self, options): s = service.MultiService() pool = threadpool.ThreadPool() reactor.callWhenRunning(pool.start) reactor.addSystemEventTrigger('after', 'shutdown', pool.stop) root = wsgi.WSGIResource(reactor, pool, wsgi_param.application) site = server.Site(root) strports.service('tcp:8000', site).setServiceParent(s) ts = internet.TimerService(1, update, wsgi_param.application, reactor) ts.setServiceParent(s) return s
def postApplication(self): """ Start the application and run the reactor. """ service.IService(self.application).privilegedStartService() app.startApplication(self.application, not self.config['no_save']) app.startApplication(internet.TimerService(0.1, lambda: None), 0) app.runReactorWithLogging(self.config, self.oldstdout, self.oldstderr) app.reportProfile(self.config['report-profile'], service.IProcess(self.application).processName) log.msg("Server Shut Down.")
def testTimerLoops(self): l = [] def trigger(data, number, d): l.append(data) if len(l) == number: d.callback(l) d = defer.Deferred() self.t = internet.TimerService(0.01, trigger, "hello", 10, d) self.t.startService() d.addCallback(self.assertEqual, ['hello'] * 10) d.addCallback(lambda x : self.t.stopService()) return d