Пример #1
0
def main():
    args = get_argparser().parse_args()
    init_logger(args)
    if os.name == "nt":
        loop = asyncio.ProactorEventLoop()
        asyncio.set_event_loop(loop)
    else:
        loop = asyncio.get_event_loop()
    atexit.register(lambda: loop.close())

    ddb = FlatFileDB(args.ddb)
    pdb = FlatFileDB(args.pdb)
    rtr = Notifier(dict())
    log = Log(1000)

    if args.git:
        repo_backend = GitBackend(args.repository)
    else:
        repo_backend = FilesystemBackend(args.repository)
    repository = Repository(repo_backend, log.log)
    atexit.register(repository.close)
    repository.scan_async()

    worker_handlers = {
        "get_device": ddb.get,
        "get_parameter": pdb.get,
        "set_parameter": pdb.set,
        "update_rt_results": lambda mod: process_mod(rtr, mod),
        "log": log.log
    }
    scheduler = Scheduler(get_last_rid() + 1, worker_handlers, repo_backend)
    worker_handlers["scheduler_submit"] = scheduler.submit
    scheduler.start()
    atexit.register(lambda: loop.run_until_complete(scheduler.stop()))

    server_control = Server({
        "master_ddb": ddb,
        "master_pdb": pdb,
        "master_schedule": scheduler,
        "master_repository": repository
    })
    loop.run_until_complete(server_control.start(
        args.bind, args.port_control))
    atexit.register(lambda: loop.run_until_complete(server_control.stop()))

    server_notify = Publisher({
        "schedule": scheduler.notifier,
        "devices": ddb.data,
        "parameters": pdb.data,
        "rt_results": rtr,
        "explist": repository.explist,
        "log": log.data
    })
    loop.run_until_complete(server_notify.start(
        args.bind, args.port_notify))
    atexit.register(lambda: loop.run_until_complete(server_notify.stop()))

    loop.run_forever()
Пример #2
0
 async def listen(self):
     data = None
     while True:
         obj = await self.read_pyon()
         try:
             action = obj["action"]
             if action == "terminate":
                 self.close_cb()
                 return
             elif action == "mod":
                 mod = obj["mod"]
                 if mod["action"] == "init":
                     data = self.init_cb(mod["struct"])
                 else:
                     process_mod(data, mod)
                 self.mod_cb(mod)
             else:
                 raise ValueError("unknown action in parent message")
         except:
             logger.error("error processing parent message", exc_info=True)
             self.close_cb()
Пример #3
0
 async def listen(self):
     data = None
     while True:
         obj = await self.read_pyon()
         try:
             action = obj["action"]
             if action == "terminate":
                 self.close_cb()
                 return
             elif action == "mod":
                 mod = obj["mod"]
                 if mod["action"] == "init":
                     data = self.init_cb(mod["struct"])
                 else:
                     process_mod(data, mod)
                 self.mod_cb(mod)
             else:
                 raise ValueError("unknown action in parent message")
         except:
             logger.error("error processing parent message",
                          exc_info=True)
             self.close_cb()
Пример #4
0
 def update(self, mod):
     process_mod(self.model, mod)
     for notify_cb in self.notify_cbs:
         notify_cb(mod)
Пример #5
0
 def update(self, mod):
     process_mod(self.data, mod)
Пример #6
0
 def update(self, mod):
     # Copy mod before applying to avoid sharing references to objects
     # between this and the DatasetManager, which would lead to mods being
     # applied twice.
     process_mod(self.data, copy.deepcopy(mod))
Пример #7
0
 def update(self, mod):
     # Copy mod before applying to avoid sharing references to objects
     # between this and the DatasetManager, which would lead to mods being
     # applied twice.
     process_mod(self.data, copy.deepcopy(mod))
Пример #8
0
 def update(self, mod):
     target = self.groups[self.current_group]["data"]
     process_mod(target, mod)
Пример #9
0
 def update(self, mod):
     process_mod(self.data, mod)
Пример #10
0
 def update(self, mod):
     process_mod(self.model, mod)
     for notify_cb in self.notify_cbs:
         notify_cb(mod)