def test_get_queue_default_queue(self): u''' Test that the default queue is returned if no queue is given. ''' q = jobs.get_queue() assert_equal(jobs.remove_queue_name_prefix(q.name), jobs.DEFAULT_QUEUE_NAME)
def test_worker_default_queue(self): self.enqueue() self.enqueue(queue=u'my_queue') jobs.Worker().work(burst=True) all_jobs = self.all_jobs() assert_equal(len(all_jobs), 1) assert_equal(jobs.remove_queue_name_prefix(all_jobs[0].origin), u'my_queue')
def test_worker_multiple_queues(self): self.enqueue() self.enqueue(queue=u'queue1') self.enqueue(queue=u'queue2') jobs.Worker([u'queue1', u'queue2']).work(burst=True) all_jobs = self.all_jobs() assert_equal(len(all_jobs), 1) assert_equal(jobs.remove_queue_name_prefix(all_jobs[0].origin), jobs.DEFAULT_QUEUE_NAME)
def test_foreign_queues_are_ignored(self): u''' Test that foreign RQ-queues are ignored. ''' # Create queues for this CKAN instance self.enqueue(queue=u'q1') self.enqueue(queue=u'q2') # Create queue for another CKAN instance with changed_config(u'ckan.site_id', u'some-other-ckan-instance'): self.enqueue(queue=u'q2') # Create queue not related to CKAN rq.Queue(u'q4').enqueue_call(jobs.test_job) all_queues = jobs.get_all_queues() names = {jobs.remove_queue_name_prefix(q.name) for q in all_queues} assert_equal(names, {u'q1', u'q2'})
def job_clear(context, data_dict): '''Clear background job queues. Does not affect jobs that are already being processed. :param list queues: The queues to clear. If not given then ALL queues are cleared. :returns: The cleared queues. :rtype: list .. versionadded:: 2.7 ''' _check_access(u'job_clear', context, data_dict) queues = data_dict.get(u'queues') if queues: queues = [jobs.get_queue(q) for q in queues] else: queues = jobs.get_all_queues() names = [jobs.remove_queue_name_prefix(queue.name) for queue in queues] for queue, name in zip(queues, names): queue.empty() log.info(u'Cleared background job queue "{}"'.format(name)) return names
def test_queue_name_removal_without_prefix(self): jobs.remove_queue_name_prefix(u'foobar')
def test_queue_name_removal_with_prefix(self): plain = u'foobar' prefixed = jobs.add_queue_name_prefix(plain) assert_equal(jobs.remove_queue_name_prefix(prefixed), plain)
def test_get_queue_other_queue(self): u''' Test that a different queue can be given. ''' q = jobs.get_queue(u'my_queue') assert_equal(jobs.remove_queue_name_prefix(q.name), u'my_queue')