Example #1
0
 def test_empty(self):
     # test
     worker = WorkerThread()
     worker._empty = False
     worker._run()
     
     # verify
     with self.mysql.dao.create_session() as session:
         self.assertEqual(0, session.query(TaskModel).count())
     self.assertTrue(worker._empty)
     
Example #2
0
 def test_error(self):
     # set up
     with self.mysql.dao.create_session() as session:
         session.add(TaskModel(args=json.dumps({'a': 1, 'b': 0}), eta=datetime(2000, 1, 1), name='queue_test.worker_test.foo', queue='queue1', retries=0))
         
     # test
     worker = WorkerThread()
     worker._empty = True
     worker._run()
     
     # verify
     with self.mysql.dao.create_session() as session:
         task = session.query(TaskModel).one()
         self.assertEqual(1, task.retries)
         self.assertAlmostNow(task.eta - timedelta(minutes=1))
Example #3
0
 def test_success(self):
     # set up
     with self.mysql.dao.create_session() as session:
         session.add(TaskModel(args=json.dumps({'a': 1, 'b': 3}), eta=datetime(2000, 1, 1), name='worker_test.foo', queue='queue1', retries=0))
         
     # test
     worker = WorkerThread()
     worker._empty = True
     worker._run()
     
     # verify
     self.assertEqual(4, foo.result)
     with self.mysql.dao.create_session() as session:
         self.assertEqual(0, session.query(TaskModel).count())
     self.assertFalse(worker._empty)
Example #4
0
def start(queue, dao):
    from mqueue import db
    from mqueue.scheduler import SchedulerThread
    from mqueue.worker import WorkerThread
    
    init(queue)
    db.dao = dao
    modutil.load_tree('tasks')
    
    worker = WorkerThread()
    worker.start()
    scheduler = SchedulerThread()
    scheduler.start()
    
    _wait_for_exit()
    
    worker.stop()
    scheduler.stop()