示例#1
0
    def __call__(self):
        status = 1
        with log_exception(status=1):
            args = self.parser.parse_args()
            log_args(args)
            config.log_cached()
            logger = getLogger('django')

            with ExitStack() as stack:
                if self._pid_file:
                    stack.enter_context(
                        pid_file(dirname=config.PID_DIR,
                                 max_age=self._pid_file_max_age))

                if self._stoppable:
                    self._stoppable_instance = stoppable()
                    stack.enter_context(self._stoppable_instance)

                status = self.run(args, logger) or 0
        sys.exit(status)
示例#2
0
def normal_run(pf):
    with pid_file(filename=pf) as p, stoppable() as s:
        while s.go_on:
            sleep(0.01)
示例#3
0
def nasty_process():
    with stoppable() as s:
        while True:
            sleep(0.01)
示例#4
0
def nice_process():
    with stoppable() as s:
        while s.check_stop():
            sleep(0.01)
示例#5
0

def get_login_link(member, browser, path):
    redirect = get_public_url(path)
    access_token = create_access_token(
        "localhost",
        browser,
        member.member_id,
        valid_duration=timedelta(days=4))['access_token']
    return get_public_url(f"/member/login/{access_token}?redirect=" +
                          quote_plus(redirect))


if __name__ == '__main__':

    with log_exception(status=1), stoppable():
        parser = ArgumentParser(
            description="Dispatch emails in db send queue.",
            formatter_class=ArgumentDefaultsHelpFormatter)

        parser.add_argument(
            '--sleep',
            default=4,
            help='Sleep time (in seconds) between doing ant work.')
        parser.add_argument(
            '--limit',
            default=10,
            help='Max messages to send every time checking for messages.')

        args = parser.parse_args()