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 #15

Closed Shaokun-X closed 2 hours ago

Shaokun-X commented 2 hours 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 2 hours ago

My bad, it was just because the arg of the old task was in string, this works perfectly already. Deeply sorry for the disturbance 😬