How to use huey - 10 common examples

To help you get started, we’ve selected a few huey examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github coleifer / huey / examples / django_ex / djangoex / test_app / tasks.py View on Github external
@periodic_task(crontab(minute='*/2'))
def every_other_minute():
    tprint('This task runs every 2 minutes.', 35)
github coleifer / huey / examples / django_ex / one_queue / test_app / tasks.py View on Github external
@task(retries=3, retry_delay=10)
def try_thrice():
    if random.randint(1, 3) == 1:
        print('OK')
    else:
        print('About to fail, will retry in 10 seconds')
        raise Exception('Crap something went wrong')
github scoutapp / scout_apm_python / tests / integration / test_huey.py View on Github external
def retry_once():
        if not retry_once._did_retry:
            retry_once._did_retry = True
            raise RetryTask()
        return "Done."
github scoutapp / scout_apm_python / tests / integration / test_huey.py View on Github external
def app_with_scout(scout_config=None):
    """
    Context manager that configures a Huey app with Scout installed.
    """
    # Enable Scout by default in tests.
    if scout_config is None:
        scout_config = {}
    scout_config.setdefault("monitor", True)
    scout_config["core_agent_launch"] = False

    huey = MemoryHuey(immediate=True)

    @huey.task()
    @huey.lock_task("hello")
    def hello():
        return "Hello World!"

    @huey.task()
    def retry_once():
        if not retry_once._did_retry:
            retry_once._did_retry = True
            raise RetryTask()
        return "Done."

    retry_once._did_retry = False

    @huey.task()
github jeffmvr / mangle-vpn / mangle / common / tasks.py View on Github external
@db_task()
def send_email(recipient, subject, body, sender):
    """
    Sends the given application e-mail.
    :return: None
    """
    if not mail.init():
        logger.error("email failed: SMTP not configured")

    msg = EmailMultiAlternatives(subject, body, sender, (recipient, ))
    msg.attach_alternative(body, "text/html")

    if msg.send() == 0:
        logger.error("email failed: %s - '%s'", recipient, subject)
    else:
        logger.info("email sent: %s - '%s'", recipient, subject)
github coleifer / huey / huey / contrib / simple.py View on Github external
def respond(self, data):
        if not isinstance(data, list):
            try:
                data = data.split()
            except:
                raise CommandError('Unrecognized request type.')

        if not isinstance(data[0], basestring):
            raise CommandError('First parameter must be command name.')

        command = data[0].upper()
        if command not in self._commands:
            raise CommandError('Unrecognized command: %s' % command)
        else:
            logger.debug('Received %s', decode(command))

        return self._commands[command](*data[1:])
github coleifer / huey / huey / contrib / simple.py View on Github external
def respond(self, data):
        if not isinstance(data, list):
            try:
                data = data.split()
            except:
                raise CommandError('Unrecognized request type.')

        if not isinstance(data[0], basestring):
            raise CommandError('First parameter must be command name.')

        command = data[0].upper()
        if command not in self._commands:
            raise CommandError('Unrecognized command: %s' % command)
        else:
            logger.debug('Received %s', decode(command))

        return self._commands[command](*data[1:])