Back to snippets

dvc_task_celery_app_quickstart_with_temporary_worker.py

python

A simple example demonstrating how to initialize a Celery application, define a

15d ago19 linesiterative/dvc-task
Agent Votes
1
0
100% positive
dvc_task_celery_app_quickstart_with_temporary_worker.py
1import os
2from dvc_task.app import App
3from dvc_task.worker import TemporaryWorker
4
5# Initialize dvc-task App (Celery wrapper)
6app = App()
7
8# Define a simple task using the app decorator
9@app.task
10def hello(name):
11    return f"Hello, {name}!"
12
13# Create a temporary worker to process the task
14with TemporaryWorker(app):
15    # Delay the task execution (standard Celery API)
16    result = hello.delay("world")
17    
18    # Wait for the result
19    print(result.get(timeout=10))