"""Úloha pro součet dvou hodnot.""" from huey import RedisHuey from time import sleep huey = RedisHuey() @huey.task() def add(a, b): """Úloha pro součet dvou hodnot.""" sleep(5) return a + b
def __init__(self): self.config = config self.db = DB(config) self.huey = RedisHuey(host="redis", result_store=False) self.web3 = Web3(HTTPProvider(config.HTTP_PROVIDER_URL))
class BrokenRedisStorage(RedisStorage): def dequeue(self): raise ValueError('broken redis dequeue') broken_redis_storage = BrokenRedisStorage() class BrokenHuey(Huey): def get_storage(self): return broken_redis_storage dummy_huey = DummyHuey() test_huey = RedisHuey('testing', blocking=False, read_timeout=0.1) # Logger used by the consumer. logger = logging.getLogger('huey.consumer') # Create a log handler that will track messages generated by the consumer. class CaptureLogs(logging.Handler): def __init__(self, *args, **kwargs): self.messages = [] logging.Handler.__init__(self, *args, **kwargs) def emit(self, record): self.messages.append(record.getMessage()) def __enter__(self):
from huey import RedisHuey huey_instance = RedisHuey(url='tcp://backend:6379')
import os from huey import RedisHuey from pyramid.paster import get_appsettings redis_url = os.environ.get('REDIS_URL', 'redis://127.0.0.1:6379/9') paster_config = get_appsettings(os.environ.get('APP_CONFIG_FILE', 'development.ini')) huey = RedisHuey('canopus', url=redis_url)
import random import requests import smtplib import time from ipaddress import ip_address import tldextract from github import Github from huey import RedisHuey, crontab from pymongo import errors, DESCENDING, ASCENDING from config.database import result_col, query_col, blacklist_col, notice_col, github_col, setting_col, REDIS_HOST, \ REDIS_PORT from utils.date import timestamp from utils.log import logger from utils.notice import mail_notice huey = RedisHuey('hawkeye', host=REDIS_HOST, port=int(REDIS_PORT)) base_path = os.path.split(os.path.realpath(__file__))[0] extract = tldextract.TLDExtract(cache_file='{}/.tld_set'.format(base_path)) if setting_col.count({'key': 'task', 'minute': {'$exists': True}, 'page': {'$exists': True}}): minute = int(setting_col.find_one({'key': 'task'}).get('minute')) setting_col.update_one({'key': 'task'}, {'$set': {'key': 'task', 'pid': os.getpid(), 'last': timestamp()}}, upsert=True) else: minute = 10 setting_col.update_one({'key': 'task'}, {'$set': {'key': 'task', 'pid': os.getpid(), 'minute': 10, 'page': 3, 'last': timestamp()}}, upsert=True)
import datetime import pickle from huey import crontab from huey import exceptions as huey_exceptions from huey import RedisHuey from huey.api import Huey from huey.api import QueueTask from huey.constants import EmptyData from huey.registry import registry from huey.storage import RedisStorage from huey.tests.base import b from huey.tests.base import BaseTestCase from huey.utils import local_to_utc huey = RedisHuey(result_store=False, events=False, blocking=False) huey_results = RedisHuey(blocking=False, max_errors=10) huey_store_none = RedisHuey(store_none=True, blocking=False) # Global state. state = {} @huey.task() def put_data(key, value): state[key] = value @huey.task(include_task=True) def put_data_ctx(key, value, task=None): state['last_task_class'] = type(task).__name__ @huey_results.task(include_task=True)
import settings from service import create_xml from huey import RedisHuey, crontab huey = RedisHuey('feedXML', host=settings.REDIS_HOST) @huey.periodic_task(crontab(minute='0', hour=settings.CRONTAB_HOUR)) def task(): create_xml()
from log_config import logging_config, dictConfig dictConfig(logging_config) from redis.connection import ConnectionPool from huey import RedisHuey from settings import REDIS_URL redis_pool = ConnectionPool.from_url(REDIS_URL) docker_huey = RedisHuey('docker_huey', connection_pool=redis_pool)
""" Setup for the Huey task queue. """ # pylint: disable=invalid-name,ungrouped-imports,unused-import from os import environ # run consumer via: # huey_consumer.py app.huey # from the root of the app directory # ------------------------------------------------------ # Huey task config # ------------------------------------------------------ # Redis is the preferred Huey backend REDIS_URL = environ.get('REDIS_URL', None) if REDIS_URL: from huey import RedisHuey huey = RedisHuey(url=REDIS_URL) # But in dev environments, fall back to SqliteHuey if Redis is not available else: try: import peewee except ImportError: MSG = "peewee is required for SqliteHuey." MSG += "Install peewee directly, don't add to requirements.txt" raise RuntimeError(MSG) from huey import SqliteHuey huey = SqliteHuey(filename='huey.db')
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # --------------------------------------------------------------------------- # # Imports # --------------------------------------------------------------------------- # from huey import RedisHuey from huey.signals import SIGNAL_COMPLETE # --------------------------------------------------------------------------- # # Definitions # --------------------------------------------------------------------------- # queue = RedisHuey("tasker", host="localhost") # --------------------------------------------------------------------------- # # Tasks # --------------------------------------------------------------------------- # @queue.task() def execute(a, b): return a + b @queue.signal(SIGNAL_COMPLETE) def on_complete(sig, task, *_): """ Do Some Task if is completed """ pass
'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'queue_service.wsgi.application' pool = ConnectionPool(host='redis://redis', port=6379, max_connections=20) HUEY = RedisHuey('queue-api', connection_pool=pool) # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'postgres', 'USER': '******', 'HOST': 'db', 'PORT': 5432, } } # Password validation
from huey import RedisHuey huey = RedisHuey('queue', host='localhost')
#!/usr/bin/env python # -*- coding: utf-8 -*- # Survaider import hug from huey import RedisHuey from mongoengine import connect as mongo_connect from jupiter._config import version, redis_params, mongo_params, mongo_dbi huey = RedisHuey(**redis_params) mongo_connect(mongo_dbi, **mongo_params) # Register Huey tasks import jupiter.tasks.periodic import jupiter.tasks.utils @hug.get('/', versions=1) def index(): return "Survaider" # Register APIs from jupiter.api import ( hooks as api_hooks, tasks as api_tasks, )
def patch_huey(g): from huey import RedisHuey from redis import ConnectionPool pool = ConnectionPool.from_url(env.REDIS_URL) g['HUEY'] = RedisHuey('danceschool', connection_pool=pool)