mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-18 14:16:45 +00:00
Try with logging
This commit is contained in:
parent
fbb262fe88
commit
00b09cd07d
1 changed files with 12 additions and 12 deletions
|
@ -16,7 +16,7 @@ from bookwyrm import models, settings
|
|||
from bookwyrm.tasks import app
|
||||
|
||||
# remove after testing in Github Actions
|
||||
import sys
|
||||
import logging
|
||||
|
||||
|
||||
IMG_WIDTH = settings.PREVIEW_IMG_WIDTH
|
||||
|
@ -308,12 +308,12 @@ def generate_preview_image(
|
|||
|
||||
|
||||
def save_and_cleanup(image, instance=None):
|
||||
sys.stdout.write("/start save_and_cleanup")
|
||||
logging.warn("/start save_and_cleanup")
|
||||
|
||||
if instance:
|
||||
sys.stdout.write("\nInstance OK, ")
|
||||
logging.warn("\nInstance OK, ")
|
||||
file_name = "%s-%s.jpg" % (str(instance.id), str(uuid4()))
|
||||
sys.stdout.write("%s, " % file_name)
|
||||
logging.warn("%s, " % file_name)
|
||||
image_buffer = BytesIO()
|
||||
|
||||
try:
|
||||
|
@ -322,7 +322,7 @@ def save_and_cleanup(image, instance=None):
|
|||
except ValueError:
|
||||
old_path = ""
|
||||
|
||||
sys.stdout.write("path: %s, " % old_path)
|
||||
logging.warn("path: %s, " % old_path)
|
||||
|
||||
# Save
|
||||
image.save(image_buffer, format="jpeg", quality=75)
|
||||
|
@ -334,18 +334,18 @@ def save_and_cleanup(image, instance=None):
|
|||
image_buffer.tell(),
|
||||
None,
|
||||
)
|
||||
sys.stdout.write("before save: %sx" % instance.preview_image.width)
|
||||
sys.stdout.write("%s, " % instance.preview_image.height)
|
||||
logging.warn("before save: %sx" % instance.preview_image.width)
|
||||
logging.warn("%s, " % instance.preview_image.height)
|
||||
|
||||
save_without_broadcast = isinstance(instance, (models.Book, models.User))
|
||||
if save_without_broadcast:
|
||||
instance.save(update_fields=["preview_image"], broadcast=False)
|
||||
instance.save(broadcast=False)
|
||||
else:
|
||||
instance.save(update_fields=["preview_image"])
|
||||
instance.save()
|
||||
|
||||
instance.refresh_from_db()
|
||||
sys.stdout.write("after save: %sx" % instance.preview_image.width)
|
||||
sys.stdout.write("%s\n" % instance.preview_image.height)
|
||||
logging.warn("after save: %sx" % instance.preview_image.width)
|
||||
logging.warn("%s\n" % instance.preview_image.height)
|
||||
|
||||
# Clean up old file after saving
|
||||
if os.path.exists(old_path):
|
||||
|
@ -353,7 +353,7 @@ def save_and_cleanup(image, instance=None):
|
|||
finally:
|
||||
image_buffer.close()
|
||||
|
||||
sys.stdout.write("end save_and_cleanup/\n")
|
||||
logging.warn("end save_and_cleanup/\n")
|
||||
|
||||
@app.task
|
||||
def generate_site_preview_image_task():
|
||||
|
|
Loading…
Reference in a new issue