Try logging output

This commit is contained in:
Joachim 2021-05-29 13:44:43 +02:00
parent cc0881b11c
commit fbb262fe88
2 changed files with 19 additions and 0 deletions

View file

@ -15,6 +15,9 @@ from django.db.models import Avg
from bookwyrm import models, settings from bookwyrm import models, settings
from bookwyrm.tasks import app from bookwyrm.tasks import app
# remove after testing in Github Actions
import sys
IMG_WIDTH = settings.PREVIEW_IMG_WIDTH IMG_WIDTH = settings.PREVIEW_IMG_WIDTH
IMG_HEIGHT = settings.PREVIEW_IMG_HEIGHT IMG_HEIGHT = settings.PREVIEW_IMG_HEIGHT
@ -305,8 +308,12 @@ def generate_preview_image(
def save_and_cleanup(image, instance=None): def save_and_cleanup(image, instance=None):
sys.stdout.write("/start save_and_cleanup")
if instance: if instance:
sys.stdout.write("\nInstance OK, ")
file_name = "%s-%s.jpg" % (str(instance.id), str(uuid4())) file_name = "%s-%s.jpg" % (str(instance.id), str(uuid4()))
sys.stdout.write("%s, " % file_name)
image_buffer = BytesIO() image_buffer = BytesIO()
try: try:
@ -315,6 +322,8 @@ def save_and_cleanup(image, instance=None):
except ValueError: except ValueError:
old_path = "" old_path = ""
sys.stdout.write("path: %s, " % old_path)
# Save # Save
image.save(image_buffer, format="jpeg", quality=75) image.save(image_buffer, format="jpeg", quality=75)
instance.preview_image = InMemoryUploadedFile( instance.preview_image = InMemoryUploadedFile(
@ -325,6 +334,8 @@ def save_and_cleanup(image, instance=None):
image_buffer.tell(), image_buffer.tell(),
None, None,
) )
sys.stdout.write("before save: %sx" % instance.preview_image.width)
sys.stdout.write("%s, " % instance.preview_image.height)
save_without_broadcast = isinstance(instance, (models.Book, models.User)) save_without_broadcast = isinstance(instance, (models.Book, models.User))
if save_without_broadcast: if save_without_broadcast:
@ -332,12 +343,17 @@ def save_and_cleanup(image, instance=None):
else: else:
instance.save(update_fields=["preview_image"]) instance.save(update_fields=["preview_image"])
instance.refresh_from_db()
sys.stdout.write("after save: %sx" % instance.preview_image.width)
sys.stdout.write("%s\n" % instance.preview_image.height)
# Clean up old file after saving # Clean up old file after saving
if os.path.exists(old_path): if os.path.exists(old_path):
os.remove(old_path) os.remove(old_path)
finally: finally:
image_buffer.close() image_buffer.close()
sys.stdout.write("end save_and_cleanup/\n")
@app.task @app.task
def generate_site_preview_image_task(): def generate_site_preview_image_task():

View file

@ -177,6 +177,9 @@ USE_L10N = True
USE_TZ = True USE_TZ = True
NOSE_ARGS = ['--nocapture',
'--nologcapture',]
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/ # https://docs.djangoproject.com/en/3.2/howto/static-files/