queue cat render on save

This commit is contained in:
Seth Ladygo
2019-05-17 02:08:57 -07:00
parent d54e3dfc5a
commit 899194da5e
2 changed files with 16 additions and 1 deletions

View File

@ -70,4 +70,6 @@ def save_catalog(request):
cat.data['id'] = cat.id
cat.save()
cat.queue_render()
return JsonResponse(cat.data, safe=False)

View File

@ -6,7 +6,7 @@ import re
from django.conf import settings
from django.contrib.postgres.fields import JSONField
from django.db import models
from django.db import models, connections
from products.models import Product
@ -178,3 +178,16 @@ class Catalog(models.Model):
materials = materials.union(set(block.get('ids', [])))
return materials
def queue_render(self):
"""Create a pdf render job for us in the queue."""
job_state = 'new'
job_class = 'Appy::Queue::ProCatalogRenderJob'
job_args = { 'id': self.id }
job_sql = 'insert into job_queue (state,job_class,job_args) values(%s,%s,%s)'
job_params = [job_state, job_class, json.dumps(job_args)]
with connections['products'].cursor() as cursor:
cursor.execute(job_sql, job_params)