Пример #1
0
    def delete_current_buried_job(self, client_id, tube):
        if self.beanstalk_clients.get(client_id):
            client = self.beanstalk_clients[client_id].client
            yield client.watch(tube)

            job = yield client.peek_buried()
            browsers = self.beanstalk_clients[client_id].browsers
            if isinstance(job, beanstalkt.CommandFailed):  # no job
                return

            yield client.delete(job["id"])

            next_job = yield client.peek_buried()
            if isinstance(next_job, beanstalkt.CommandFailed):  # no job
                message = dict(type="delete-current-buried-job",
                               data=dict(next_job=None))
                self.broadcast(browsers, message)
                return

            job_info = yield client.stats_job(next_job["id"])
            stats_tube = yield client.stats_tube(tube)

            message = dict(type="delete-current-buried-job",
                           data=dict(next_job=job_info, stats_tube=stats_tube))
            self.broadcast(browsers, message)
Пример #2
0
    def delete_current_buried_job(self, client_id, tube):
        if self.beanstalk_clients.get(client_id):
            client = self.beanstalk_clients[client_id].client
            yield client.watch(tube)

            job = yield client.peek_buried()
            browsers = self.beanstalk_clients[client_id].browsers
            if isinstance(job, beanstalkt.CommandFailed):  # no job
                return

            yield client.delete(job["id"])

            next_job = yield client.peek_buried()
            if isinstance(next_job, beanstalkt.CommandFailed):  # no job
                message = dict(type="delete-current-buried-job",
                               data=dict(next_job=None))
                self.broadcast(browsers, message)
                return

            job_info = yield client.stats_job(next_job["id"])
            stats_tube = yield client.stats_tube(tube)

            message = dict(type="delete-current-buried-job",
                           data=dict(next_job=job_info,
                                     stats_tube=stats_tube))
            self.broadcast(browsers, message)
Пример #3
0
    def delete_all_delayed_jobs(self, client_id, tube):
        if self.beanstalk_clients.get(client_id):
            client = self.beanstalk_clients[client_id].client
            yield client.watch(tube)
            num = yield client.kick()
            if num == 0:
                return
            job = yield client.reserve(timeout=0)
            browsers = self.beanstalk_clients[client_id].browsers

            stats_tube = yield client.stats_tube(tube)
            jobs_total = stats_tube["current-jobs-delayed"]
            while job:
                if isinstance(job, beanstalkt.TimedOut):  # no job
                    break

                yield client.delete(job["id"])
                stats_tube = yield client.stats_tube(tube)
                jobs_current = stats_tube["current-jobs-delayed"]
                percent = 100.0 * jobs_current / jobs_total
                message = dict(type="delete-delayed-job-progress",
                               data=100 - percent)
                self.broadcast(browsers, message)

                num = yield client.kick()
                if num == 0:
                    break

                job = yield client.reserve(timeout=0)
Пример #4
0
 def add_browser(self, browser_id, page):
     if not self.browsers.get(browser_id):
         self.browsers[browser_id] = dict(pages=set(),
                                          clients=set(),
                                          )
     self.browsers[browser_id].pages.add(page)
     self.stats()
Пример #5
0
    def delete_all_delayed_jobs(self, client_id, tube):
        if self.beanstalk_clients.get(client_id):
            client = self.beanstalk_clients[client_id].client
            yield client.watch(tube)
            num = yield client.kick()
            if num == 0:
                return
            job = yield client.reserve(timeout=0)
            browsers = self.beanstalk_clients[client_id].browsers

            stats_tube = yield client.stats_tube(tube)
            jobs_total = stats_tube["current-jobs-delayed"]
            while job:
                if isinstance(job, beanstalkt.TimedOut):  # no job
                    break

                yield client.delete(job["id"])
                stats_tube = yield client.stats_tube(tube)
                jobs_current = stats_tube["current-jobs-delayed"]
                percent = 100.0 * jobs_current / jobs_total
                message = dict(type="delete-delayed-job-progress",
                               data=100 - percent)
                self.broadcast(browsers, message)

                num = yield client.kick()
                if num == 0:
                    break

                job = yield client.reserve(timeout=0)
Пример #6
0
 def add_browser(self, browser_id, page):
     if not self.browsers.get(browser_id):
         self.browsers[browser_id] = dict(
             pages=set(),
             clients=set(),
         )
     self.browsers[browser_id].pages.add(page)
     self.stats()
Пример #7
0
    def __init__(self, handler):
        handlers = handler
        settings = dict(
            debug=True,
            template_path="templates",
            static_path="static",
        )

        super(Application, self).__init__(handlers, **settings)
Пример #8
0
    def __init__(self, handler):
        handlers = handler
        settings = dict(
            debug=True,
            template_path="templates",
            static_path="static",
        )

        super(Application, self).__init__(handlers, **settings)
Пример #9
0
    def add_client(self, host, port, browser_id):

        client_id = self.client_id.format(host=host, port=port)

        if not self.beanstalk_clients.get(client_id):
            client = beanstalkt.Client(host, port)
            self.beanstalk_clients[client_id] = dict(client=client,
                                                     browsers=set())

        self.beanstalk_clients[client_id].browsers.add(browser_id)

        self.browsers[browser_id].clients.add(client_id)
        yield client.connect()
Пример #10
0
    def add_client(self, host, port, browser_id):

        client_id = self.client_id.format(host=host, port=port)

        if not self.beanstalk_clients.get(client_id):
            client = beanstalkt.Client(host, port)
            self.beanstalk_clients[client_id] = dict(client=client,
                                                     browsers=set())

        self.beanstalk_clients[client_id].browsers.add(browser_id)

        self.browsers[browser_id].clients.add(client_id)
        yield client.connect()
Пример #11
0
    def delete_all_buried_jobs(self, client_id, tube):
        if self.beanstalk_clients.get(client_id):
            client = self.beanstalk_clients[client_id].client
            yield client.watch(tube)
            job = yield client.peek_buried()
            browsers = self.beanstalk_clients[client_id].browsers

            stats_tube = yield client.stats_tube(tube)
            jobs_total = stats_tube["current-jobs-buried"]
            while job:
                if isinstance(job, beanstalkt.CommandFailed):  # no job
                    break

                yield client.delete(job["id"])
                stats_tube = yield client.stats_tube(tube)
                jobs_current = stats_tube["current-jobs-buried"]
                percent = 100.0 * jobs_current / jobs_total
                message = dict(type="delete-buried-job-progress",
                               data=100 - percent)
                self.broadcast(browsers, message)

                job = yield client.peek_buried()
Пример #12
0
    def delete_all_buried_jobs(self, client_id, tube):
        if self.beanstalk_clients.get(client_id):
            client = self.beanstalk_clients[client_id].client
            yield client.watch(tube)
            job = yield client.peek_buried()
            browsers = self.beanstalk_clients[client_id].browsers

            stats_tube = yield client.stats_tube(tube)
            jobs_total = stats_tube["current-jobs-buried"]
            while job:
                if isinstance(job, beanstalkt.CommandFailed):  # no job
                    break

                yield client.delete(job["id"])
                stats_tube = yield client.stats_tube(tube)
                jobs_current = stats_tube["current-jobs-buried"]
                percent = 100.0 * jobs_current / jobs_total
                message = dict(type="delete-buried-job-progress",
                               data=100 - percent)
                self.broadcast(browsers, message)

                job = yield client.peek_buried()
Пример #13
0
 def __init__(self):
     # "host:port": {client:client, browsers=set(}
     self.beanstalk_clients = dict()
     # browser_id: {pages: set(page), clients:set("host:port")}
     self.browsers = dict()
Пример #14
0
    def on_message(self, message):
        try:
            message = json_decode(message)
        except ValueError:
            return
        data = message["data"]
        msg_type = message["type"]
        print message["type"]
        if msg_type == "browser-new":  # client join first
            browser_id = str(uuid.uuid4())
            result = dict(type="client-new",
                          data=dict(
                              id=browser_id
                          ))
            self.send(json_encode(result))

            self.browser_id = browser_id
            clients.add_browser(browser_id, self)
        elif msg_type == "browser-back":
            browser_id = data["id"]

            self.browser_id = browser_id
            clients.add_browser(browser_id, self)
        elif msg_type == "server-add":
            host = data["host"]
            port = data["port"]
            yield clients.add_client(host, port, self.browser_id)
        elif msg_type == "stats":
            yield clients.stats()
        elif msg_type == "list-tubes":
            client_id = data
            yield clients.list_tubes(client_id)
        elif msg_type == "stats-tube":
            client_id = data["client_id"]
            tube_name = data["tube_name"]
            yield clients.stats_tube(client_id, tube_name)
        elif msg_type == "refresh-tube":
            client_id = data
            yield clients.auto_refresh_tubes(client_id)
        elif msg_type == "delete-all-ready-jobs":
            client_id = data["client_id"]
            tube_name = data["tube_name"].strip()
            yield clients.delete_all_ready_jobs(client_id, tube_name)
        elif msg_type == "delete-current-ready-job":
            client_id = data["client_id"]
            tube_name = data["tube_name"].strip()
            yield clients.delete_current_ready_job(client_id, tube_name)
        elif msg_type == "delete-current-delayed-job":
            client_id = data["client_id"]
            tube_name = data["tube_name"].strip()
            yield clients.delete_current_delayed_job(client_id, tube_name)
        elif msg_type == "delete-all-delayed-jobs":
            client_id = data["client_id"]
            tube_name = data["tube_name"].strip()
            yield clients.delete_all_delayed_jobs(client_id, tube_name)
        elif msg_type == "delete-current-buried-job":
            client_id = data["client_id"]
            tube_name = data["tube_name"].strip()
            yield clients.delete_current_buried_job(client_id, tube_name)
        elif msg_type == "delete-all-buried-jobs":
            client_id = data["client_id"]
            tube_name = data["tube_name"].strip()
            yield clients.delete_all_buried_jobs(client_id, tube_name)

        else:
            print "undefined message type:", message["type"]
Пример #15
0
    def on_message(self, message):
        try:
            message = json_decode(message)
        except ValueError:
            return
        data = message["data"]
        msg_type = message["type"]
        print message["type"]
        if msg_type == "browser-new":  # client join first
            browser_id = str(uuid.uuid4())
            result = dict(type="client-new", data=dict(id=browser_id))
            self.send(json_encode(result))

            self.browser_id = browser_id
            clients.add_browser(browser_id, self)
        elif msg_type == "browser-back":
            browser_id = data["id"]

            self.browser_id = browser_id
            clients.add_browser(browser_id, self)
        elif msg_type == "server-add":
            host = data["host"]
            port = data["port"]
            yield clients.add_client(host, port, self.browser_id)
        elif msg_type == "stats":
            yield clients.stats()
        elif msg_type == "list-tubes":
            client_id = data
            yield clients.list_tubes(client_id)
        elif msg_type == "stats-tube":
            client_id = data["client_id"]
            tube_name = data["tube_name"]
            yield clients.stats_tube(client_id, tube_name)
        elif msg_type == "refresh-tube":
            client_id = data
            yield clients.auto_refresh_tubes(client_id)
        elif msg_type == "delete-all-ready-jobs":
            client_id = data["client_id"]
            tube_name = data["tube_name"].strip()
            yield clients.delete_all_ready_jobs(client_id, tube_name)
        elif msg_type == "delete-current-ready-job":
            client_id = data["client_id"]
            tube_name = data["tube_name"].strip()
            yield clients.delete_current_ready_job(client_id, tube_name)
        elif msg_type == "delete-current-delayed-job":
            client_id = data["client_id"]
            tube_name = data["tube_name"].strip()
            yield clients.delete_current_delayed_job(client_id, tube_name)
        elif msg_type == "delete-all-delayed-jobs":
            client_id = data["client_id"]
            tube_name = data["tube_name"].strip()
            yield clients.delete_all_delayed_jobs(client_id, tube_name)
        elif msg_type == "delete-current-buried-job":
            client_id = data["client_id"]
            tube_name = data["tube_name"].strip()
            yield clients.delete_current_buried_job(client_id, tube_name)
        elif msg_type == "delete-all-buried-jobs":
            client_id = data["client_id"]
            tube_name = data["tube_name"].strip()
            yield clients.delete_all_buried_jobs(client_id, tube_name)

        else:
            print "undefined message type:", message["type"]
Пример #16
0
 def __init__(self):
     # "host:port": {client:client, browsers=set(}
     self.beanstalk_clients = dict()
     # browser_id: {pages: set(page), clients:set("host:port")}
     self.browsers = dict()