ostark / craft-async-queue

Async Queue Handler for Craft 3 and 4
MIT License
93 stars 7 forks source link

Fail to generate PDF attachment to emails in Craft Commerce using craft-async-queue #35

Closed thinkflo closed 3 years ago

thinkflo commented 3 years ago

First of all, thank you for writing this great plugin. In this case, I need craft-async-queue because of the way Craft Commerce uses the Queue to send Status event emails, such as when an Order is placed. The problem I am having is that when you attach a PDF (which is a Craft generated invoice) to the email, craft-async-queue does it's job and sends out the email promptly, however, when craft-async-queue is handling the queue, the PDF attachment is always corrupted. It provides a blank PDF file with the single line contained:

An error occurred while processing the PDF.

When I disable craft-async-queue, the PDF gets emailed successfully. This is completely reproducible by just turning the plugin on and off. On: almost immediately sent email but corrupted PDF. Off: good PDF, but painfully slow email send by having to click around in the admin to initializing the queue job with Craft's native methods.

I tried digging through storage/logs/queue.log and storage/logs/web.log and phperrors, and even through all the system log files in /var/log to try to trace down where this is failing but there is no record of any failure in any of the logs. I tried grepping pdf in all of them and nadda.

I know that Craft Commerce uses dompdf behind the scenes to perform the PDF generation. I suspect that the daemon that craft-async-queue sets up is having either tmp file creation, or permission based or relative path issues in being able to successfully generate the PDF but I cannot find any clue to where the error is actually occurring.

I thought I would open an issue in case you could help me figure out where the problem might be occurring and in case others either have/had this same problem and have solved it or are in the same boat.

In case it helps, I'm using Craft Pro 3.5.12, Craft Commerce Pro 3.2.7, AsyncQueue 2.1.1 on stock Ubuntu 20.04.1 LTS running nginx/1.18.0 and PHP 7.4.3 with php-fpm. Dompdf version that is installed is 0.8.6

Help?

ostark commented 3 years ago

Hi @thinkflo,

Can you reproduce the issue when running the process in the foreground?

  1. disable the plugin
  2. set runQueueAutomatically to false, in general.php
  3. run php craft queue/run -v
  4. Inject a job
thinkflo commented 3 years ago

Hi there,

Didn't do it in exact sequential order. I did 2, 1, 4, 3.

And, I got a corrupted PDF. Doesn't seem to be a problem with the plugin after all. Still wondering how I can find the log of where it's failing though.

Thanks for the help!