You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support for computed columns and indexes for MSSQL backend JSON-based results column #9501
I’m currently using Celery with MSSQL as the result backend, and I’ve modified the results column to store JSON instead of binary (see #8634). I’d like to add computed columns to help index and query the JSON data more efficiently, but I’m unsure if this is officially supported within the Celery framework or if it could break anything.
thx @auvipy ... I was thinking probably the database models need to be converted into something more extensible, while still keeping the needed fields in place.
do you have any suggestions how to approach this?
I'm also not sure if the schema is checked each time and aligned, in case of upgrades or changes for example.
for example, wondering about something like this, but not sure if this is a proper way to override the backend. Maybe there is a better way to do it.
# celery_custom.pyfromceleryimportCeleryfromcelery.backends.databaseimportDatabaseBackendfromcelery.backends.database.modelsimportTaskfromsqlalchemyimportColumn, String, Integer# 1. Define a mixin that supplies additional fields.classAdditionalFieldsMixin:
# Add any extra fields you require.extra_field=Column(String(255), nullable=True)
another_field=Column(Integer, default=0, nullable=False)
# 2. Create a custom Task model that includes the additional fields.# We use multiple inheritance to combine our mixin with Celery's Task model.classCustomTask(AdditionalFieldsMixin, Task):
# We keep the same table name to act as a drop-in replacement.__tablename__=Task.__tablename__# 3. Create a custom database backend that uses the custom Task model.classCustomDatabaseBackend(DatabaseBackend):
# Override the TaskModel to point to our custom model.TaskModel=CustomTask# 4. Setup a Celery application and configure it to use a database backend.# Note: For this example we are using an SQLite database.app=Celery('my_app', broker='pyamqp://guest@localhost//', backend='db+sqlite:///results.sqlite')
# Override the default backend with our custom backend.app.backend=CustomDatabaseBackend(app=app)
@app.taskdefadd(x, y):
"""Simple task that adds two numbers."""returnx+yif__name__=='__main__':
# Submit a task and print its result.result=add.delay(4, 6)
print("Task result:", result.get(timeout=10))
Activity
auvipy commentedon Feb 24, 2025
contributions are welcome
dxdc commentedon Feb 24, 2025
thx @auvipy ... I was thinking probably the database models need to be converted into something more extensible, while still keeping the needed fields in place.
do you have any suggestions how to approach this?
I'm also not sure if the schema is checked each time and aligned, in case of upgrades or changes for example.
https://github.com/celery/celery/blob/main/celery/backends/database/models.py
dxdc commentedon Feb 24, 2025
for example, wondering about something like this, but not sure if this is a proper way to override the backend. Maybe there is a better way to do it.
auvipy commentedon Feb 27, 2025
Mmm... May be a 3 rd party extension is well suited for MsSQL specific features for now
dxdc commentedon Feb 27, 2025
Is there a recommended place in the code to be able to plugin and develop an interface like that? I could see general utility for it.
I don't know how well it will persist with version upgrades otherwise.
auvipy commentedon Mar 9, 2025
In that case, i suggest to open a draft PR for review and further discussion in celery 🙂 it will be the easiest I guess
feat(db-backend): add schema extension support for Task/TaskSet tables
feat(db-backend): add schema extension support for Task/TaskSet tables