I’m using ChromicPDF in my application to allow a user to download a pdf. In my application, I have a button they can click that sends a request to my controller which generates the pdf with ChromicPDF and sends it back to the user with send_download
from the controller.
ChomicPDF docs state:
To increase or limit the number of concurrent workers, you can pass pool configuration to the supervisor. Please note that this is a non-queueing session pool. If you intend to max it out, you will need a job queue as well.
I was able to generate the error in testing:
** (ChromicPDF.Browser.ExecutionError) Caught EXIT signal from NimblePool.checkout!/4
** (EXIT) time out
This means that your operation was unable to acquire a worker from the pool
within 5000ms, as all workers are currently occupied.
You're experiencing this error randomly under load. This would indicate that
the number of concurrent print jobs exceeds the total number of workers in
the pool, so that all workers are occupied.
To fix this, you need to increase your resources, e.g. by increasing the number
of workers with the `session_pool: [size: ...]` option.
However, please be aware that while ChromicPDF (by virtue of the underlying
NimblePool worker pool) does perform simple queueing of worker checkouts,
it is not suitable as a proper job queue. If you expect to peaks in your load
leading to a high level of concurrent use of your PDF printing component,
a job queue like Oban will provide a better experience.
The error message suggests Oban. However, I’m not sure Oban is the best option for a couple reasons:
- Oban isn’t designed for the caller to block awaiting the result of the job. However, it does have the concept of a Notifier which can be used to return the pdf to the controller process to send back to the user.
- I would prefer not to rebuild the
conn
andassigns
within the job because I’m reusing some functions in my controller. But I also don’t want to pass the results of ChromicPDF.Template.source_and_options/1 to the job directly.
The other options I’ve looked at are:
Any suggestions for the best option to queue the pdf printing work when I don’t want the work to be done in the background?