File: other.py

package info (click to toggle)
celery 5.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,008 kB
  • sloc: python: 64,346; sh: 795; makefile: 378
file content (62 lines) | stat: -rw-r--r-- 1,813 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from __future__ import annotations

import os

import pytest
from pytest_celery import CeleryTestWorker, defaults
from pytest_docker_tools import build, container, fxtr

from celery import Celery
from t.smoke.workers.dev import SmokeWorkerContainer


class OtherSmokeWorkerContainer(SmokeWorkerContainer):
    """Alternative worker with different name and queue, but same configurations for the rest."""

    @classmethod
    def worker_name(cls) -> str:
        return "other_smoke_tests_worker"

    @classmethod
    def worker_queue(cls) -> str:
        return "other_smoke_tests_queue"


# Build the image like the dev worker
celery_other_dev_worker_image = build(
    path=".",
    dockerfile="t/smoke/workers/docker/dev",
    tag="t/smoke/worker:other",
    buildargs=OtherSmokeWorkerContainer.buildargs(),
)


# Define container settings like the dev worker
other_dev_worker_container = container(
    image="{celery_other_dev_worker_image.id}",
    environment=fxtr("default_worker_env"),
    network="{default_pytest_celery_network.name}",
    volumes={
        # Volume: Worker /app
        "{default_worker_volume.name}": defaults.DEFAULT_WORKER_VOLUME,
        # Mount: Celery source
        os.path.abspath(os.getcwd()): {
            "bind": "/celery",
            "mode": "rw",
        },
    },
    wrapper_class=OtherSmokeWorkerContainer,
    timeout=defaults.DEFAULT_WORKER_CONTAINER_TIMEOUT,
    command=OtherSmokeWorkerContainer.command(),
)


@pytest.fixture
def celery_other_dev_worker(
    other_dev_worker_container: OtherSmokeWorkerContainer,
    celery_setup_app: Celery,
) -> CeleryTestWorker:
    """Creates a pytest-celery worker node from the worker container."""
    worker = CeleryTestWorker(other_dev_worker_container, app=celery_setup_app)
    yield worker
    worker.teardown()