def process_background_tasks(): """Discover and run background tasks in the common app.""" for path, func in TASKS.items(): import_module(path) pending_tasks = Task.objects.filter(task_name='.'.join([path, func])) for task in pending_tasks: task_manager.run_task(task)
def mocked_run_task(name, args=None, kwargs=None): """ We mock tasks.run_task to give other threads some time to update the database. Otherwise we run into a locked database. """ val = tasks.run_task(name, args, kwargs) if app_settings.BACKGROUND_TASK_RUN_ASYNC: time.sleep(1) return val
def mocked_run_task(name, args=None, kwargs=None): """ We mock tasks.run_task to give other threads some time to update the database. Otherwise we run into a locked database. """ val = tasks.run_task(name, args, kwargs) if app_settings.BACKGROUND_TASK_RUN_ASYNC: time.sleep(1) return val
def test_run_task(self): tasks.run_task(self.proxy.name, [], {}) self.assertEqual(((), {}), _recorded.pop()) tasks.run_task(self.proxy.name, ['hi'], {}) self.assertEqual((('hi', ), {}), _recorded.pop()) tasks.run_task(self.proxy.name, [], {'kw': 1}) self.assertEqual(((), {'kw': 1}), _recorded.pop())
def test_run_task(self): tasks.run_task(self.proxy.name, [], {}) self.assertEqual(((), {}), _recorded.pop()) tasks.run_task(self.proxy.name, ['hi'], {}) self.assertEqual((('hi',), {}), _recorded.pop()) tasks.run_task(self.proxy.name, [], {'kw': 1}) self.assertEqual(((), {'kw': 1}), _recorded.pop())
def test_run_task(self): tasks.run_task(self.proxy.name, [], {}) self.assertEqual(((), {}), _recorded.pop())
class TestTaskProxy(unittest.TestCase): def setUp(self): super(TestTaskProxy, self).setUp() self.proxy = tasks.background()(record_task) def test_run_task(self): tasks.run_task(self.proxy.name, [], {}) self.assertEqual(((), {}), _recorded.pop()) tasks.run_task(self.proxy.name, ['hi'], {}) self.assertEqual((('hi',), {}), _recorded.pop()) tasks.run_task(self.proxy.name, [], {'kw': 1}) self.assertEqual(((), {'kw': 1}), _recorded.pop())