ZeitOnline / celery_longterm_scheduler

Schedules celery tasks to run in the potentially far future
BSD 3-Clause "New" or "Revised" License
27 stars 8 forks source link

Support kombu serialization and deserialization #15

Open Shaokun-X opened 1 month ago

Shaokun-X commented 1 month ago

Normal Celery tasks support using kombu to register object types to serialize/deserialize automatically:

from kombu.utils.json import register_type
from django.db.models import Model
from django.apps import apps

# Allow serialization of django models:
register_type(
    Model,
    "model",
    lambda o: [o._meta.label, o.pk],
    lambda o: apps.get_model(o[0]).objects.get(pk=o[1]),
)

@shared_task
def mytask(model: Model):
    # this will be the restored the object
    print(type(model))

But it seems celery_longterm_scheduler is not taking it into account. Is it possible to add this feature?

kombu doc: https://docs.celeryq.dev/projects/kombu/en/stable/userguide/serialization.html

Shaokun-X commented 1 month ago

After some more testing, I think with celery_longterm_scheduler, kombu deserialization is not working properly