def get_tiger(): """ Sets up logging and returns a new tasktiger instance. """ structlog.configure( logger_factory=structlog.stdlib.LoggerFactory(), wrapper_class=structlog.stdlib.BoundLogger, ) logging.basicConfig(format='%(message)s') conn = redis.Redis(db=TEST_DB, decode_responses=True) tiger = TaskTiger(connection=conn, config={ # We need this 0 here so we don't pick up scheduled tasks when # doing a single worker run. 'SELECT_TIMEOUT': 0, 'ACTIVE_TASK_UPDATE_TIMEOUT': 2 * DELAY, 'REQUEUE_EXPIRED_TASKS_INTERVAL': DELAY, 'LOCK_RETRY': DELAY * 2., 'DEFAULT_RETRY_METHOD': fixed(DELAY, 2), 'BATCH_QUEUES': { 'batch': 3, }, 'SINGLE_WORKER_QUEUES': ['swq'], }) tiger.log.setLevel(logging.CRITICAL) return tiger
def get_tiger(): """ Sets up logging and returns a new tasktiger instance. """ structlog.configure( logger_factory=structlog.stdlib.LoggerFactory(), wrapper_class=structlog.stdlib.BoundLogger, ) logging.basicConfig(format='%(message)s') conn = redis.Redis(db=TEST_DB) tiger = TaskTiger(connection=conn, config={ # We need this 0 here so we don't pick up scheduled tasks when # doing a single worker run. 'SELECT_TIMEOUT': 0, 'LOCK_RETRY': DELAY*2., 'DEFAULT_RETRY_METHOD': fixed(DELAY, 2), 'BATCH_QUEUES': { 'batch': 3, } }) tiger.log.setLevel(logging.CRITICAL) return tiger
def get_tiger(): """ Sets up logging and returns a new tasktiger instance. """ structlog.configure( logger_factory=structlog.stdlib.LoggerFactory(), wrapper_class=structlog.stdlib.BoundLogger, ) logging.basicConfig(format='%(message)s') conn = redis.Redis(db=TEST_DB) tiger = TaskTiger( connection=conn, config={ # We need this 0 here so we don't pick up scheduled tasks when # doing a single worker run. 'SELECT_TIMEOUT': 0, 'LOCK_RETRY': DELAY * 2., 'DEFAULT_RETRY_METHOD': fixed(DELAY, 2), 'BATCH_QUEUES': { 'batch': 3, } }) tiger.log.setLevel(logging.CRITICAL) return tiger
def test_retry_method_fixed(self): f = fixed(2, 3) assert f[0](1, *f[1]) == 2 assert f[0](2, *f[1]) == 2 assert f[0](3, *f[1]) == 2 pytest.raises(StopRetry, f[0], 4, *f[1])
import logging import redis import structlog from tasktiger import TaskTiger, Worker, fixed from .config import DELAY, TEST_DB TEST_TIGER_CONFIG = { # We need this 0 here so we don't pick up scheduled tasks when # doing a single worker run. 'SELECT_TIMEOUT': 0, 'ACTIVE_TASK_UPDATE_TIMEOUT': 2 * DELAY, 'REQUEUE_EXPIRED_TASKS_INTERVAL': DELAY, 'LOCK_RETRY': DELAY * 2., 'DEFAULT_RETRY_METHOD': fixed(DELAY, 2), 'BATCH_QUEUES': { 'batch': 3, }, 'SINGLE_WORKER_QUEUES': ['swq'], 'EXCLUDE_QUEUES': ['periodic_ignore'], } class Patch(object): """ Simple context manager to patch a function, e.g.: with Patch(module, 'func_name', mocked_func): module.func_name() # will use mocked_func module.func_name() # will use the original function
def test_retry_method_fixed(self): f = fixed(2, 3) assert f[0](1, *f[1]) == 2 assert f[0](2, *f[1]) == 2 assert f[0](3, *f[1]) == 2 pytest.raises(StopRetry, f[0], 4, *f[1])