-
Notifications
You must be signed in to change notification settings - Fork 2
Trans article #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trans article #28
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This will make sure the app is always imported when | ||
# Django starts so that shared_task will use this app. | ||
from django.conf import settings | ||
|
||
if settings.CELERY_ALWAYS_EAGER is False: | ||
from .celery import app as celery_app | ||
__all__ = ('celery_app',) | ||
else: | ||
__all__ = () |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,41 @@ | ||||||||||||||||||||||||||||||
import logfire | ||||||||||||||||||||||||||||||
from celery import Celery | ||||||||||||||||||||||||||||||
from celery.signals import worker_init, beat_init | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
app = Celery('proj') | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
# Using a string here means the worker doesn't have to serialize | ||||||||||||||||||||||||||||||
# the configuration object to child processes. | ||||||||||||||||||||||||||||||
# - namespace='CELERY' means all celery-related configuration keys | ||||||||||||||||||||||||||||||
# should have a `CELERY_` prefix. | ||||||||||||||||||||||||||||||
app.config_from_object('django.conf:settings', namespace='CELERY') | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
# Load task modules from all registered Django apps. | ||||||||||||||||||||||||||||||
app.autodiscover_tasks() | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
@worker_init.connect() | ||||||||||||||||||||||||||||||
def init_worker(*args, **kwargs): | ||||||||||||||||||||||||||||||
logfire.configure(service_name="celery-worker", send_to_logfire='if-token-present') | ||||||||||||||||||||||||||||||
logfire.instrument_celery() | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
@beat_init.connect() | ||||||||||||||||||||||||||||||
def init_beat(*args, **kwargs): | ||||||||||||||||||||||||||||||
logfire.configure(service_name="celery-beat", send_to_logfire='if-token-present') | ||||||||||||||||||||||||||||||
logfire.instrument_celery() | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
@app.task | ||||||||||||||||||||||||||||||
def add(x: int, y: int): | ||||||||||||||||||||||||||||||
return x + y | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
add.delay(42, 50) | ||||||||||||||||||||||||||||||
Comment on lines
+28
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Remove task execution at module level. Executing the task at module import time will cause connection errors during Django startup, as evidenced by the pipeline failure. @app.task
def add(x: int, y: int):
+ """Add two integers and return the result."""
return x + y
-add.delay(42, 50) If you need to test the task, consider adding it to a management command or view instead. 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Pylint (3.3.7)[convention] 29-29: Missing function or method docstring (C0116) 🪛 GitHub Actions: pk web site backend testing[error] 32-32: Celery task 'add.delay(42, 50)' failed due to kombu.exceptions.OperationalError: [Errno 111] Connection refused. The AMQP connection to the message broker could not be established. 🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
app.conf.beat_schedule = { | ||||||||||||||||||||||||||||||
"add-every-30-seconds": { | ||||||||||||||||||||||||||||||
"task": "tasks.add", | ||||||||||||||||||||||||||||||
"schedule": 30.0, | ||||||||||||||||||||||||||||||
"args": (16, 16), | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
Comment on lines
+35
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainFix beat schedule task reference. The task reference is incorrect and will cause the scheduled task to fail. -app.conf.beat_schedule = {
+app.conf.beat_schedule = {
"add-every-30-seconds": {
- "task": "tasks.add",
+ "task": "pythonkr_backend.celery.add",
"schedule": 30.0,
"args": (16, 16),
},
} 🏁 Script executed: #!/bin/bash
# Verify the correct task path for the beat schedule
# Description: Check if there are other task definitions that might affect the correct path
ast-grep --pattern '@$_.task
def $_($_) {
$$$
}' Length of output: 52 To determine the correct import path for your Celery task, let’s locate where 🏁 Script executed: #!/bin/bash
# Find all Celery task definitions and look for `add`
rg -n -E '@(app\.task|shared_task)' --glob '*.py' -C3
rg -n 'def add' --glob '*.py' -C3 Length of output: 921 Update beat_schedule to use the fully qualified task name The • File: pythonkr_backend/pythonkr_backend/celery.py -app.conf.beat_schedule = {
- "add-every-30-seconds": {
- "task": "tasks.add",
- "schedule": 30.0,
- "args": (16, 16),
- },
-}
+app.conf.beat_schedule = {
+ "add-every-30-seconds": {
+ "task": "pythonkr_backend.celery.add",
+ "schedule": 30.0,
+ "args": (16, 16),
+ },
+} 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Pylint (3.3.7)[convention] 35-35: Trailing whitespace (C0303) [convention] 41-41: Final newline missing (C0304) 🤖 Prompt for AI Agents
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify AI package versions and compatibility.
The addition of
pydantic-ai-slim[anthropic,openai]>=0.2.6
looks appropriate for AI functionality.🌐 Web query:
💡 Result:
The latest version of pydantic-ai-slim is 0.2.12, released on May 29, 2025[1]. This package serves as an agent framework/shim to use Pydantic with large language models (LLMs), offering a slimmer version with minimal required dependencies.
Optional Extras
Pydantic-ai-slim provides several optional dependency groups that can be installed based on your specific needs:
logfire
— installs thelogfire
PyPI packageevals
— installs thepydantic-evals
PyPI packageopenai
— installs theopenai
PyPI packagevertexai
— installsgoogle-auth
andrequests
PyPI packagesanthropic
— installs theanthropic
PyPI packagegroq
— installs thegroq
PyPI packagemistral
— installs themistralai
PyPI packagecohere
— installs thecohere
PyPI packageduckduckgo
— installs theduckduckgo-search
PyPI packagetavily
— installs thetavily-python
PyPI package[2]You can install multiple extras simultaneously using the syntax:
or
anthropic
andopenai
extras cover all needed LLM providers.• Databricks ML Runtime 16.3ML ships
requests==2.32.2
(pydantic-ai-slim needs ≥2.32.3).• AWS Lambda/serverless may require
slim: false
to include package metadata.ModelResponse.usage
andModel.request
return types.📝 Committable suggestion
🤖 Prompt for AI Agents