本文整理汇总了Python中twisted.application.internet.TimerService类的典型用法代码示例。如果您正苦于以下问题:Python TimerService类的具体用法?Python TimerService怎么用?Python TimerService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TimerService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: application
def application(config):
app = Application("Scrapyd")
http_port = config.getint('http_port', 6800)
portal = Portal(PublicHTMLRealm(config, app), [FilePasswordDB(str(config.get('passwd', '')))])
credentialFactory = DigestCredentialFactory("md5", "Go away")
poller = QueuePoller(config)
eggstorage = FilesystemEggStorage(config)
scheduler = SpiderScheduler(config)
environment = Environment(config)
app.setComponent(IPoller, poller)
app.setComponent(IEggStorage, eggstorage)
app.setComponent(ISpiderScheduler, scheduler)
app.setComponent(IEnvironment, environment)
launcher = Launcher(config, app)
timer = TimerService(5, poller.poll)
webservice = TCPServer(http_port, server.Site(HTTPAuthSessionWrapper(portal, [credentialFactory])))
log.msg("Scrapyd web console available at http://localhost:%s/" % http_port)
launcher.setServiceParent(app)
timer.setServiceParent(app)
webservice.setServiceParent(app)
return app
示例2: stopService
def stopService(self):
"""
Stop this service. This will release buckets partitions it holds
"""
TimerService.stopService(self)
if self.kz_partition.acquired:
return self.kz_partition.finish()
示例3: __init__
def __init__(self, kz_client, interval, partitioner_path, buckets,
time_boundary, log, got_buckets,
clock=None):
"""
:param log: a bound log
:param kz_client: txKazoo client
:param partitioner_path: ZooKeeper path, used for partitioning
:param buckets: iterable of buckets to distribute between
nodes. Ideally there should be at least as many elements as nodes
taking part in this partitioner. This should be a sequence of str.
:param time_boundary: time to wait for partitioning to stabilize.
:param got_buckets: Callable which will be called with a list of
buckets when buckets have been allocated to this node.
:param clock: clock to use for checking the buckets on an interval.
"""
MultiService.__init__(self)
self.kz_client = kz_client
self.partitioner_path = partitioner_path
self.buckets = buckets
self.log = log
self.got_buckets = got_buckets
self.time_boundary = time_boundary
ts = TimerService(interval, self.check_partition)
ts.setServiceParent(self)
ts.clock = clock
self._old_buckets = []
示例4: __init__
def __init__(self, basedir="."):
node.Node.__init__(self, basedir)
self.started_timestamp = time.time()
self.logSource="Client"
self.DEFAULT_ENCODING_PARAMETERS = self.DEFAULT_ENCODING_PARAMETERS.copy()
self.init_introducer_client()
self.init_stats_provider()
self.init_secrets()
self.init_storage()
self.init_control()
self.helper = None
if self.get_config("helper", "enabled", False, boolean=True):
self.init_helper()
self._key_generator = KeyGenerator()
key_gen_furl = self.get_config("client", "key_generator.furl", None)
if key_gen_furl:
self.init_key_gen(key_gen_furl)
self.init_client()
# ControlServer and Helper are attached after Tub startup
self.init_ftp_server()
self.init_sftp_server()
hotline_file = os.path.join(self.basedir,
self.SUICIDE_PREVENTION_HOTLINE_FILE)
if os.path.exists(hotline_file):
age = time.time() - os.stat(hotline_file)[stat.ST_MTIME]
self.log("hotline file noticed (%ds old), starting timer" % age)
hotline = TimerService(1.0, self._check_hotline, hotline_file)
hotline.setServiceParent(self)
# this needs to happen last, so it can use getServiceNamed() to
# acquire references to StorageServer and other web-statusable things
webport = self.get_config("node", "web.port", None)
if webport:
self.init_web(webport) # strports string
示例5: application
def application(config):
app = Application("Scrapyd")
http_port = config.getint('http_port', 6800)
bind_address = config.get('bind_address', '0.0.0.0')
poller = QueuePoller(config)
eggstorage = FilesystemEggStorage(config)
scheduler = SpiderScheduler(config)
environment = Environment(config)
app.setComponent(IPoller, poller)
app.setComponent(IEggStorage, eggstorage)
app.setComponent(ISpiderScheduler, scheduler)
app.setComponent(IEnvironment, environment)
laupath = config.get('launcher', 'scrapyd.launcher.Launcher')
laucls = load_object(laupath)
launcher = laucls(config, app)
timer = TimerService(5, poller.poll)
webservice = TCPServer(http_port, server.Site(Root(config, app)), interface=bind_address)
log.msg("Scrapyd web console available at http://%s:%s/" % (bind_address, http_port))
launcher.setServiceParent(app)
timer.setServiceParent(app)
webservice.setServiceParent(app)
return app
示例6: application
def application(config):
app = Application("Scrapyd")
http_port = config.getint('http_port', 6800)
poller = QueuePoller(config)
eggstorage = FilesystemEggStorage(config)
scheduler = SpiderScheduler(config)
environment = Environment(config)
app.setComponent(IPoller, poller)
app.setComponent(IEggStorage, eggstorage)
app.setComponent(ISpiderScheduler, scheduler)
app.setComponent(IEnvironment, environment)
launcher = Launcher(config, app)
timer = TimerService(5, poller.poll)
root = Root(config, app)
root = configRoot(root, config)
webservice = TCPServer(http_port, server.Site(root))
log.msg("Scrapyd web console available at http://localhost:%s/" % http_port)
launcher.setServiceParent(app)
timer.setServiceParent(app)
webservice.setServiceParent(app)
return app
示例7: setup_selfheal_service
def setup_selfheal_service(clock, config, dispatcher, health_checker, log):
"""
Setup selfheal timer service and return it.
:param clock: :obj:`IReactorTime` provider
:param dict config: Configuration dict containing selfheal info
:param dispatcher: Effect dispatcher
:param health_checker: ``HealthChecker`` object where SelfHeal's health
check will be added
:param log: :obj:`BoundLog` logger used by service
:return: selfheal service or None if relevant config is not found
:rtype: :obj:`IService`
"""
if "selfheal" not in config:
return None
interval = get_in(["selfheal", "interval"], config, no_default=True)
selfheal = SelfHeal(clock, dispatcher, config_value, interval, log)
func, lock = zk.locked_logged_func(
dispatcher, "/selfheallock", log, "selfheal-lock-acquired",
selfheal.setup)
health_checker.checks["selfheal"] = zk.create_health_check(lock)
sh_timer = TimerService(interval, func)
sh_timer.clock = clock
return sh_timer
示例8: get_application
def get_application(config):
app = Application('Scrapyd')
http_port = config.getint('http_port', 6800)
bind_address = config.get('bind_address', '0.0.0.0')
poll_interval = config.getfloat('poll_interval', 5)
poller = QueuePoller(config)
eggstorage = FilesystemEggStorage(config)
scheduler = SpiderScheduler(config)
environment = Environment(config)
app.setComponent(IPoller, poller)
app.setComponent(IEggStorage, eggstorage)
app.setComponent(ISpiderScheduler, scheduler)
app.setComponent(IEnvironment, environment)
laupath = config.get('launcher', 'scrapyd_mongodb.launcher.Launcher')
laucls = load_object(laupath)
launcher = laucls(config, app)
timer = TimerService(poll_interval, poller.poll)
webservice = TCPServer(
http_port, server.Site(Root(config, app)),
interface=bind_address)
log.msg('http://%(bind_address)s:%(http_port)s/' % {'bind_address':bind_address, 'http_port':http_port})
launcher.setServiceParent(app)
timer.setServiceParent(app)
webservice.setServiceParent(app)
return app
示例9: application
def application(config, components=interfaces):
app = Application("Scrapyd")
http_port = config.getint('http_port', 6800)
bind_address = config.get('bind_address', '0.0.0.0')
for interface, key in interfaces:
path = config.get(key)
cls = load_object(path)
component = cls(config)
app.setComponent(interface, component)
poller = component
laupath = config.get('launcher', 'scrapyd.launcher.Launcher')
laucls = load_object(laupath)
launcher = laucls(config, app)
poll_every = config.getint("poll_every", 5)
timer = TimerService(poll_every, poller.poll)
webservice = TCPServer(http_port, server.Site(Root(config, app)), interface=bind_address)
log.msg(format="Scrapyd web console available at http://%(bind_address)s:%(http_port)s/",
bind_address=bind_address, http_port=http_port)
launcher.setServiceParent(app)
timer.setServiceParent(app)
webservice.setServiceParent(app)
return app
示例10: application
def application(config):
app = Application("Scrapyd")
http_port = int(environ.get('PORT', config.getint('http_port', 6800)))
config.cp.set('scrapyd', 'database_url', environ.get('DATABASE_URL'))
poller = Psycopg2QueuePoller(config)
eggstorage = FilesystemEggStorage(config)
scheduler = Psycopg2SpiderScheduler(config)
environment = Environment(config)
app.setComponent(IPoller, poller)
app.setComponent(IEggStorage, eggstorage)
app.setComponent(ISpiderScheduler, scheduler)
app.setComponent(IEnvironment, environment)
launcher = Launcher(config, app)
timer = TimerService(5, poller.poll)
webservice = TCPServer(http_port, server.Site(Root(config, app)))
log.msg("Scrapyd web console available at http://localhost:%s/ (HEROKU)"
% http_port)
launcher.setServiceParent(app)
timer.setServiceParent(app)
webservice.setServiceParent(app)
return app
示例11: startService
def startService(self):
"""
Start this service. This will start buckets partitioning
"""
self.kz_partition = self.kz_client.SetPartitioner(
self.zk_partition_path, set=set(self.buckets),
time_boundary=self.time_boundary)
TimerService.startService(self)
示例12: __init__
def __init__(self, reactor):
MultiService.__init__(self)
self._deployment_state = DeploymentState()
timer = TimerService(1, self._wipe_expired)
timer.clock = reactor
timer.setServiceParent(self)
self._information_wipers = pmap()
self._clock = reactor
示例13: __init__
def __init__(self, poller=None, step=300):
"""
"""
if poller is None:
raise RuntimeError('poller cannot be None')
if not issubclass(type(poller), IPoll):
raise TypeError('poller privided is not a subclass of IPoll')
self._poller = poller
TimerService.__init__(self, step=step, callable=self._poller.poll)
示例14: __init__
def __init__(self, poller=None, step=60*5):
""" The magic here is calling the TimerService constructor (old
style class) to set the polling interval and specify the polling
function.
"""
if poller is None:
raise RuntimeError('poller cannot be None')
if not issubclass(type(poller), IPoll):
raise TypeError('poller provided is not a subclass of IPoll');
self._poller = poller
TimerService.__init__(self, step=step, callable=self._poller.poll)
示例15: __init__
def __init__(self, reactor, interval, k8s, namespace, router):
TimerService.__init__(
self,
interval,
divert_errors_to_log(self._check_once, u"router-update"),
k8s,
namespace,
)
# This attribute controls the the reactor used by TimerService to set
# up the LoopingCall.
self.clock = reactor
self._router = router