How to use the celery.uuid function in celery

To help you get started, we’ve selected a few celery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github celery / celery / t / unit / tasks / test_result.py View on Github external
def test_join_native(self):
        backend = SimpleBackend()
        results = [self.app.AsyncResult(uuid(), backend=backend)
                   for i in range(10)]
        ts = self.app.GroupResult(uuid(), results)
        ts.app.backend = backend
        backend.ids = [result.id for result in results]
        res = ts.join_native()
        assert res == list(range(10))
        callback = Mock(name='callback')
        assert not ts.join_native(callback=callback)
        callback.assert_has_calls([
            call(r.id, i) for i, r in enumerate(ts.results)
        ])
github celery / celery / t / unit / tasks / test_result.py View on Github external
def test_get_nested_without_native_join(self):
        backend = SimpleBackend()
        backend.supports_native_join = False
        ts = self.app.GroupResult(uuid(), [
            MockAsyncResultSuccess(uuid(), result='1.1',
                                   app=self.app, backend=backend),
            self.app.GroupResult(uuid(), [
                MockAsyncResultSuccess(uuid(), result='2.1',
                                       app=self.app, backend=backend),
                self.app.GroupResult(uuid(), [
                    MockAsyncResultSuccess(uuid(), result='3.1',
                                           app=self.app, backend=backend),
                    MockAsyncResultSuccess(uuid(), result='3.2',
                                           app=self.app, backend=backend),
                ]),
            ]),
        ])
        ts.app.backend = backend

        vals = ts.get()
        assert vals == [
            '1.1',
            [
                '2.1',
                [
                    '3.1',
github celery / celery / t / unit / tasks / test_result.py View on Github external
def test_children_is_results(self):
        ts = self.app.GroupResult(uuid(), [self.app.AsyncResult(uuid())])
        assert ts.children is ts.results
github celery / celery / funtests / benchmarks / reqi.py View on Github external
if delivery_info:
            self.delivery_info = {
                'exchange': delivery_info.get('exchange'),
                'routing_key': delivery_info.get('routing_key'),
            }

        self.request_dict = AttributeDict(
                {'called_directly': False,
                 'callbacks': [],
                 'errbacks': [],
                 'chord': None}, **body)




tid = uuid()
hostname = socket.gethostname()
task = {'task': T.name, 'args': (), 'kwargs': {}, 'id': tid, 'flags': 0}
app = current_app._get_current_object()

m = Message(None, {}, {}, task)

ts = time()
for i in range(1000000):
    x = Request(task, hostname=hostname, app=app, task=task)
print(time() - ts)
github celery / celery / t / unit / app / test_amqp.py View on Github external
def test_raises_if_kwargs_is_not_mapping(self):
        with pytest.raises(TypeError):
            self.app.amqp.as_task_v2(uuid(), 'foo', kwargs=(1, 2, 3))
github celery / celery / t / unit / tasks / test_result.py View on Github external
def test_get_children(self):
        tid = uuid()
        x = self.app.AsyncResult(tid)
        child = [self.app.AsyncResult(uuid()).as_tuple()
                 for i in range(10)]
        x._cache = {'children': child}
        assert x.children
        assert len(x.children) == 10

        x._cache = {'status': states.SUCCESS}
        x.backend._cache[tid] = {'result': None}
        assert x.children is None
github celery / celery / t / unit / backends / test_database.py View on Github external
def test_forget(self):
        tb = DatabaseBackend(self.uri, backend='memory://', app=self.app)
        tid = uuid()
        tb.mark_as_done(tid, {'foo': 'bar'})
        tb.mark_as_done(tid, {'foo': 'bar'})
        x = self.app.AsyncResult(tid, backend=tb)
        x.forget()
        assert x.result is None
github celery / celery / t / unit / tasks / test_tasks.py View on Github external
def test_update_state_passes_request_to_backend(self):
        backend = Mock()

        @self.app.task(shared=False, backend=backend)
        def ttt():
            pass

        ttt.push_request()

        tid = uuid()
        ttt.update_state(tid, 'SHRIMMING', {'foo': 'bar'})

        backend.store_result.assert_called_once_with(
            tid, {'foo': 'bar'}, 'SHRIMMING', request=ttt.request
        )
github celery / celery / celery / backends / filesystem.py View on Github external
def __init__(self, url=None, open=open, unlink=os.unlink, sep=os.sep,
                 encoding=default_encoding, *args, **kwargs):
        super(FilesystemBackend, self).__init__(*args, **kwargs)
        self.url = url
        path = self._find_path(url)

        # We need the path and separator as bytes objects
        self.path = path.encode(encoding)
        self.sep = sep.encode(encoding)

        self.open = open
        self.unlink = unlink

        # Lets verify that we've everything setup right
        self._do_directory_test(b'.fs-backend-' + uuid().encode(encoding))
github CroceRossaItaliana / jorvik / posta / tasks.py View on Github external
messages_to_resend = Messaggio.objects.filter(pk__in=pk_tuple)
    for msg in messages_to_resend:
        pk = msg.pk

        logger.info("[forced] Controllo messaggio id=%d" % pk)

        # Controllo se il messaggio ha un task_id,
        # se presente - dimentico il task per assegnare un nuovo task_id al messaggio
        if msg.task_id is not None:
            task = AsyncResult(msg.task_id)
            task.forget()
            logger.info("[forced] Dimentico task_id %s per il messaggio id=%d" % (msg.task_id, pk))

        # Creiamo un nuovo task ID e riaccodiamo il task.
        msg.task_id = uuid()
        msg.save()

        logger.warning("[forced] Nuovo task per l'invio accodato con id=%s." % msg.task_id)

        is_sent = msg.invia(forced=True)
        if not is_sent:
            logger.error("[forced] Errore temporaneo, nuovo tentativo richiesto.")
            raise self.retry()

        # Messaggio inviato con successo.
        logger.info("[forced] Messaggio %s inviato. Rimuovo task_id e salvo." % msg.pk)

        rescheduled_tasks_id.append(msg.task_id)
        msg.task_id = None

        msg.save()