Beispiel #1
0
    def start_job(self, task):
        self.start_job_time = int(time.time())
        task['runtime'].update({
            'worker': safe_get_host('server', 'alias'),
            'thread': self.getName(),
            'start': self.start_job_time,
        })
        # 记录当前在做什么
        task['process'] = {'ident': self.ident}
        thread_context.job = task
        try:
            self.run_task = ztq_core.task_registry[task['func']]
            # started report
            report_job(comment='start the job')

            try:
                self.run_task(*task['args'], **task['kw'])
            except TypeError:
                # keyword must string is a bug in python
                if sys.version[:5] < '2.6.5':
                    raise Exception, ("We not supported %s version of python,"
                                      "Please update it to 2.6.5 or later." %
                                      sys.version[:5])
                else:
                    raise

            if task.get('callback', None):
                callback_args = task.get('callback_args', ())
                callback_kw = task.get('callback_kw', {})
                ztq_core.push_task(task['callback'], *callback_args,
                                   **callback_kw)

        except Exception, e:
            reason = traceback.format_exception(*sys.exc_info())
            # 将错误信息记录到服务器
            return_code = str(e.args[0]) if len(e.args) > 1 else 300
            task['runtime']['return'] = return_code
            task['runtime']['reason'] = reason[-11:]
            task['runtime']['end'] = int(time.time())
            ztq_core.push_runtime_error(self.queue_name, task)
            # 错误回调
            if task.get('fcallback', None):
                callback_args = task.get('fcallback_args', ())
                callback_kw = task.get('fcallback_kw', {})
                callback_kw['return_code'] = return_code
                callback_kw['return_msg'] = reason[-1]
                ztq_core.push_task(task['fcallback'], *callback_args,
                                   **callback_kw)
            # 在终端打印错误信息
            #reason.insert(0, str(datetime.datetime.today()) + '\n')
            logger.error(''.join(reason))
Beispiel #2
0
    def start_job(self, task):
        self.start_job_time = int(time.time())
        task['runtime'].update({'worker': safe_get_host('server', 'alias'),
                                'thread': self.getName(),
                                'start': self.start_job_time, })
        # 记录当前在做什么
        task['process'] = {'ident':self.ident}
        thread_context.job = task
        try:
            self.run_task = ztq_core.task_registry[task['func']]
            # started report
            report_job(comment='start the job')

            try:
                self.run_task(*task['args'], **task['kw'])
            except TypeError:
                # keyword must string is a bug in python
                if sys.version[:5] < '2.6.5':
                    raise Exception,("We not supported %s version of python,"
                        "Please update it to 2.6.5 or later."%sys.version[:5])
                else:
                    raise

            if task.get('callback', None):
                callback_args = task.get('callback_args', ())
                callback_kw = task.get('callback_kw', {})
                ztq_core.push_task(task['callback'], *callback_args, **callback_kw)

        except Exception, e:
            reason = traceback.format_exception(*sys.exc_info())
            # 将错误信息记录到服务器
            return_code = str(e.args[0]) if len(e.args) > 1 else 300
            task['runtime']['return'] = return_code
            task['runtime']['reason'] = reason[-11:]
            task['runtime']['end'] = int( time.time() )
            ztq_core.push_runtime_error(self.queue_name, task)
            # 错误回调
            if task.get('fcallback', None):
                callback_args = task.get('fcallback_args', ())
                callback_kw = task.get('fcallback_kw', {})
                callback_kw['return_code'] = return_code
                callback_kw['return_msg'] = reason[-1]
                ztq_core.push_task(task['fcallback'], *callback_args, **callback_kw)
            # 在终端打印错误信息
            #reason.insert(0, str(datetime.datetime.today()) + '\n')
            logger.error(''.join(reason))
Beispiel #3
0
    def start_job(self, task):
        self.start_job_time = int(time.time())
        task['runtime'].update({'worker': CONFIG['server']['alias'],
                                'thread': self.getName(),
                                'start': self.start_job_time, })
        # 记录当前在做什么
        task['process'] = {'ident':self.ident}
        thread_context.job = task
        try:
            # started report
            report_job(comment='start the job')
            self.run_task = ztq_core.task_registry[task['func']]
            self.run_task(*task['args'], **task['kw'])

            task['runtime']['return'] = 0
            task['runtime']['reason'] = 'success'

            if task.get('callback', None):
                callback_args = task.get('callback_args', ())
                callback_kw = task.get('callback_kw', {})
                ztq_core.push_task(task['callback'], *callback_args, **callback_kw)

        except Exception, e:
            reason = traceback.format_exception(*sys.exc_info())
            # 将错误信息记录到服务器
            try:
                return_code = str(e.args[0]) if len(e.args) > 1 else 300
            except:
                return_code = 300
            task['runtime']['return'] = return_code
            task['runtime']['reason'] = reason[-11:]
            task['runtime']['end'] = int( time.time() )
            ztq_core.push_runtime_error(self.queue_name, task)
            # 错误回调
            if task.get('fcallback', None):
                callback_args = task.get('fcallback_args', ())
                callback_kw = task.get('fcallback_kw', {})
                callback_kw['return_code'] = return_code
                callback_kw['return_msg'] = unicode(reason[-1], 'utf-8', 'ignore')
                ztq_core.push_task(task['fcallback'], *callback_args, **callback_kw)
            # 在终端打印错误信息
            #reason.insert(0, str(datetime.datetime.today()) + '\n')
            logger.error(''.join(reason))
Beispiel #4
0
    def start_job(self, task):
        self.start_job_time = int(time.time())
        task['runtime'].update({'worker': CONFIG['server']['alias'],
                                'thread': self.getName(),
                                'start': self.start_job_time, })
        # 记录当前在做什么
        task['process'] = {'ident':self.ident}
        thread_context.job = task
        try:
            # started report
            report_job(comment='start the job')
            self.run_task = ztq_core.task_registry[task['func']]
            self.run_task(*task['args'], **task['kw'])

            task['runtime']['return'] = 0
            task['runtime']['reason'] = 'success'

            if task.get('callback', None):
                callback_args = task.get('callback_args', ())
                callback_kw = task.get('callback_kw', {})
                ztq_core.push_task(task['callback'], *callback_args, **callback_kw)

        except Exception, e:
            reason = traceback.format_exception(*sys.exc_info())
            # 将错误信息记录到服务器
            try:
                return_code = str(e.args[0]) if len(e.args) > 1 else 300
            except:
                return_code = 300
            task['runtime']['return'] = return_code
            task['runtime']['reason'] = reason[-11:]
            task['runtime']['end'] = int( time.time() )
            ztq_core.push_runtime_error(self.queue_name, task)
            # 错误回调
            if task.get('fcallback', None):
                callback_args = task.get('fcallback_args', ())
                callback_kw = task.get('fcallback_kw', {})
                callback_kw['return_code'] = return_code
                callback_kw['return_msg'] = unicode(reason[-1], 'utf-8', 'ignore')
                ztq_core.push_task(task['fcallback'], *callback_args, **callback_kw)
            # 在终端打印错误信息
            #reason.insert(0, str(datetime.datetime.today()) + '\n')
            logger.error(''.join(reason))