matthewwithanm/django-imagekit

Configurable Celery serialzier

Opened this issue · 9 comments

Pickle is considered as an unsafe serializer, so support for e.g. application/json would be great.

_celery_task = task(ignore_result=True, serializer='pickle')(_generate_file)

I'll be very glad if someone is willing to provide a PR with this functionality.

Ran into this, we only accept json as serializer, for obvious reasons.

The problem is that the file object that is passed around either is too complex in parameters to correctly serialize and deserialize.

If I could somehow get the ContentType of the model, the ID and the field_name then I could reconstruct it and simply call _generate() on the field.

OK, did some searching and can get the model through: file.generator.source.instance

The problem is that I can't find the attribute name that needs to be generated:

I have a logo image field and multiple image specs that generate different thumbnails from that.

For now I can use celery-once to create a task only once per model, and then use the generator_registry.get_ids() to find out which generators there are for a given model get the model and generate the images one by one.

It works, but it's far from ideal.

q0w commented

Why can't we pass filepath to celery/any async shedule_generation method instead of file argument and then find the file by the filepath variable?

Because you need more information on how to thumbnail the image, the file itself it not enough.

q0w commented

@hvdklauw i suggest just replacing file with filepath and when file itself is needed, find it by name. Nothing else would change

for example u can find file by name before that

The file there is an ImageCacheFile, which has all the parameters on how to generate a thumbnail, the original file alone is not enough because you might use the original to generate 3 or 4 different thumbnails, so which one are you generating?

q0w commented

So no solutions?

I totally wrote my own solution that just starts a task with the app label and model name (from ContentTypes) and an id, then the task loads it and just generates all the thumbnails.