示例#1
0
class _Job(object):
    def __init__(self):
        self.log = Logger(self.__class__.__name__, fh)
        self.log.debug("Job is created")

    def execute(self, **kwargs):
        try:
            self.log.debug("Start job with kwargs=%s" % kwargs)
            self._execute(**kwargs)
            self.log.debug("Finish job successful")
        except Exception as e:
            self.log.exception("Error during job execution")
            subject = 'Tasker Information. Произошла ошибка в скрипте %s' % self.__class__.__name__
            self.log.debug(subject)
            # send_email(subject, as_text(e.message),
            #            send_from=SMTP_SETTINGS['username'],
            #            server=SMTP_SETTINGS['server'],
            #            port=SMTP_SETTINGS['port'],
            #            user=SMTP_SETTINGS['username'],
            #            passwd=SMTP_SETTINGS['password'],
            #            dest_to=ERROR_EMAILS)

    def _execute(self, **kwargs):
        raise NotImplementedError("%s._execute" % self.__class__.__name__)

    @classmethod
    def run(cls, **kwargs):
        log.debug("in _Job.run!")
        return cls().execute(**kwargs)
示例#2
0
class SchedulerController(object):
    def __init__(self, request, scheduler):
        self.log = Logger(self.__class__.__name__, fh)
        self._request = request
        self._scheduler = scheduler

    def call(self, *args, **kwargs):
        try:
            request_info = get_request_info(self._request)
            self.log.debug("Start process request: %s, %s, %s" %
                           (request_info.url, request_info.data, request_info.method))
            data = self._call(*args, **kwargs)
            self.log.debug('Finished')
            return data
        except Exception, e:
            self.log.exception('Error during %s call' % self.__class__.__name__)
            return render_template('error.html', error=e.message)  # TODO шаблон
示例#3
0
文件: index.py 项目: alexxxmen/tasker
class IndexController(object):
    def __init__(self, request, scheduler):
        self.request = request
        self.scheduler = scheduler
        self.log = Logger(self.__class__.__name__, fh)

    def call(self):
        try:
            self.log.debug("Start process request:" % self.request)
            sched_status = self.scheduler.state
            job_list = JobListController(self.request, self.scheduler).call()
            data = render_template('index.html', data=job_list, status=sched_status)
            self.log.debug("Finished")
            return data
        except Exception, e:
            self.log.exception('Error during %s call' % self.__class__.__name__)
            return render_template('error.html', errors=[e.message])
示例#4
0
fh = logging.FileHandler(os.path.join(config.LOG_TO, config.LOGGER.get('file')))
fh.setLevel(config.LOGGER.get('level'))
fh.setFormatter(config.LOGGER.get('formatter'))

log = Logger("IBotManager", fh)


modules = get_all_modules()

threads = [Thread(target=InstaBot(**get_config_from_module(module_name[:-3])).new_auto_mod,
                  name=module_name[:-3]) for module_name in modules]


for t in threads:
    try:
        log.debug("Try start '%s' bot" % t.name)
        t.start()
        log.debug("Successfully start '%s' bot." % t.name)
    except Exception as ex:
        log.exception("Error during work bot")

[t.join() for t in threads if t.is_alive()]


def stop_all_process():
    signal.alarm(1)

atexit.register(stop_all_process)
time.sleep(5)