def add_task(): task = Task() db.session.add(task) db.session.commit() q = RedisQueue('drwebtaskmgr') q.put(task.id) return jsonify({'task': task.id})
def test_rq(self): q = RedisQueue('test') self.assertTrue(q.empty()) self.assertEqual(q.qsize(), 0) q.put('test') self.assertEqual(q.qsize(), 1) self.assertEqual(q.get(), b'test')
def __init__(self, db_helper): config = configparser.ConfigParser() config.read('config.conf') self.kill_threads = False self.num_threads = 100 self.task_queue = RedisQueue(connection=Redis()) self.tasks = Queue.Queue() self.cull_count = 0 self.cull_tasks_thread = threading.Thread(target=self.cull_tasks, args=[]) self.cull_tasks_thread.start() self.db_helper = db_helper
def __init__(self, config_file: str, listener: str): """Init the Queue from config parameters""" base_path = os.path.abspath(os.path.dirname(__file__)) config_specs = base_path + '/static/specs.yml' config_default = base_path + '/static/default.yml' config = ConfigReader().parse(config_file, config_specs, config_default) config_listener = config.get('distributer') redis = Redis(config_listener['host'], config_listener['port']) if listener not in config: raise KeyError('You must have a key {} in your config with a sub-key queue'.format(listener)) self._logger = Logger('distributer', config_file) self._logger.log.debug('Distributer QueueManager called') self._logger.log.debug('Connect to queue {}'.format(config[listener]['queue'])) self._queue = RedisQueue(config[listener]['queue'], connection=redis)
#!/usr/bin/env python """ Append results from stdin to a Redis list """ import sys from rq import RedisQueue if __name__ == '__main__': rq = RedisQueue.from_config() for line in sys.stdin: result = line.strip() print(result) rq.put_result(result)
#!/usr/bin/env python3 import datetime from time import sleep from rq import RedisQueue from threading import Thread from app import db from app.models import Task from config import QUEUE_LABEL, WORKER_THREADS q = RedisQueue(QUEUE_LABEL) def task_notify(item: Task(), stop=False): """ Update model Task before and after work done :param item: Task() instance :type stop: bool """ if item and isinstance(item, Task): if not stop: item.start_time = datetime.datetime.now() print('Work {} start'.format(item.id)) else: item.exec_time = datetime.datetime.now() print('Work {} stop'.format(item.id)) db.session.add(item) db.session.commit()