Example #1
0
 def run(self):
     from sailing.core import FileTask
     
     if os.getenv("TASK_ID", None):
         task_list = FileTask.search(CONFIG.APP_NAME, "*", pattern=os.getenv("TASK_ID", None), len=5)
     else:
         task_list = FileTask.search(CONFIG.APP_NAME, "waiting", len=15)
     
     if len(task_list) == 0:
         self.sailor.idle()
         if self.daemon: 
             self.logger.info('Waiting %d seconds for idle action' % CONFIG.IDLE_INTERVAL)
             sleep(CONFIG.IDLE_INTERVAL)
     else:
         for t in task_list:
             t.status = 'running'
             try:
                 self.logger.info("start process task '%s'" % t.path)
                 self.sailor.start(t)
                 t.status = 'done'
                 self.logger.info("done process task '%s'" % t.path)
             except Exception, e:
                 t.status = 'waiting'
                 self.logger.error(trackable("Exception on task '%s'" % t))
                 
         self.sailor.waiting()
         
         if self.daemon: 
             self.logger.info('Waiting %d seconds for next round' % CONFIG.POLLING_INTERVAL)
             sleep(CONFIG.POLLING_INTERVAL)
Example #2
0
    def robot_task_tacker(self):

        self.logger.info("start task tacker...")

        from captcha.http_client import HTTPClient
        import time

        client = HTTPClient()
        while True:
            try:
                data = client.get("http://emopad.sinaapp.com/robot/app/task_list")

                self.logger.info("tracker new task:%s" % data)

                if data.strip():
                    t = new_task("webrobot")
                    for line in data.split("\n"):
                        t.add_action(line.strip())
                    t.close()
                    t.status = "waiting"
                time.sleep(30)

                from sailing.conf import settings as CONFIG

                task_list = FileTask.search(CONFIG.APP_NAME, "done", len=15)

                for t in task_list:
                    self.logger.info("remove done task:%s" % t._id)
                    # t.remove()

            except:
                pass
Example #3
0
    def robot_task_tacker(self):

        self.logger.info("start task tacker...")

        from captcha.http_client import HTTPClient
        import time
        client = HTTPClient()
        while True:
            try:
                data = client.get(
                    "http://emopad.sinaapp.com/robot/app/task_list")

                self.logger.info("tracker new task:%s" % data)

                if data.strip():
                    t = new_task("webrobot")
                    for line in data.split("\n"):
                        t.add_action(line.strip())
                    t.close()
                    t.status = 'waiting'
                time.sleep(30)

                from sailing.conf import settings as CONFIG
                task_list = FileTask.search(CONFIG.APP_NAME, "done", len=15)

                for t in task_list:
                    self.logger.info("remove done task:%s" % t._id)
                    #t.remove()

            except:
                pass
Example #4
0
    def run(self):
        from sailing.core import FileTask

        if os.getenv("TASK_ID", None):
            task_list = FileTask.search(CONFIG.APP_NAME,
                                        "*",
                                        pattern=os.getenv("TASK_ID", None),
                                        len=5)
        else:
            task_list = FileTask.search(CONFIG.APP_NAME, "waiting", len=15)

        if len(task_list) == 0:
            self.sailor.idle()
            if self.daemon:
                self.logger.info('Waiting %d seconds for idle action' %
                                 CONFIG.IDLE_INTERVAL)
                sleep(CONFIG.IDLE_INTERVAL)
            elif os.getenv("TASK_ID"):
                self.logger.info('Not found task id:%s' % os.getenv("TASK_ID"))
        else:
            for t in task_list:
                t.status = 'running'
                try:
                    self.logger.info("start process task '%s'" % t.path)
                    self.sailor.start(t)
                    t.status = 'done'
                    self.logger.info("done process task '%s'" % t.path)
                except Exception, e:
                    t.status = 'waiting'
                    self.logger.error(trackable("Exception on task '%s'" % t))

            self.sailor.waiting()

            if self.daemon:
                self.logger.info('Waiting %d seconds for next round' %
                                 CONFIG.POLLING_INTERVAL)
                sleep(CONFIG.POLLING_INTERVAL)