hooks/zmq.py
changeset 8350 e1c05bf6fdeb
parent 8211 543e1579ba0d
child 8982 6bc1c1b4473a
equal deleted inserted replaced
8349:fdb796435d7b 8350:e1c05bf6fdeb
    44         self.repo.app_instances_bus.add_subscription('delete', clear_cache_callback)
    44         self.repo.app_instances_bus.add_subscription('delete', clear_cache_callback)
    45         for address in config.get('zmq-address-sub'):
    45         for address in config.get('zmq-address-sub'):
    46             self.repo.app_instances_bus.add_subscriber(address)
    46             self.repo.app_instances_bus.add_subscriber(address)
    47         self.repo.app_instances_bus.start()
    47         self.repo.app_instances_bus.start()
    48 
    48 
       
    49 
       
    50 class ZMQRepositoryServerStopHook(hook.Hook):
       
    51     __regid__ = 'zmqrepositoryserverstop'
       
    52     events = ('server_shutdown',)
       
    53 
       
    54     def __call__(self):
       
    55         server = getattr(self.repo, 'zmq_repo_server', None)
       
    56         if server:
       
    57             self.repo.zmq_repo_server.quit()
       
    58 
       
    59 class ZMQRepositoryServerStartHook(hook.Hook):
       
    60     __regid__ = 'zmqrepositoryserverstart'
       
    61     events = ('server_startup',)
       
    62 
       
    63     def __call__(self):
       
    64         config = self.repo.config
       
    65         if config.name == 'repository':
       
    66             # start-repository command already starts a zmq repo
       
    67             return
       
    68         address = config.get('zmq-repository-address')
       
    69         if not address:
       
    70             return
       
    71         from cubicweb.server import cwzmq
       
    72         self.repo.zmq_repo_server = server = cwzmq.ZMQRepositoryServer(self.repo)
       
    73         server.connect(address)
       
    74         self.repo.threaded_task(server.run)
       
    75