xwmx / pandoc-ruby

Ruby wrapper for Pandoc
MIT License
340 stars 43 forks source link

Images failing when convert happens asynchronously #34

Closed archonic closed 5 years ago

archonic commented 5 years ago

I've narrowed down a bug in my app and found that everything is working as intended (including pandoc-ruby), except when executing in a Sidekiq background job. The export happens and produces the file but all images are missing. If I execute the same job with the same attributes in the foreground, the images are present. I doubt this is a pandoc-ruby issue but the issue's context seems most appropriate to mention here.

Has anyone else run into this? I'm playing around with the extract-media options and such and will report back if I can get PDF generation with images working in a background job.

Update: The export media flags and standalone options changed nothing. I've narrowed it down a bit further.

  Web server process Console process
Background Doesn’t work Doesn’t work
Foreground Doesn’t work Works

This is the most related issue I could find: https://github.com/mperham/sidekiq/issues/2044

It seems that someway the application is loaded is only making it work for foreground processes in the console. Images were working from the web in a background process previously. I believe this is most likely related to the upgrade to Rails 6.0 and zeitwerk (another update: opting out of zeitwerk did not change anything).

archonic commented 5 years ago

This was actually a docker network problem. Resolving "http://first.lvh.me:3000" was only working from a rails console context for (what I now realize was) obvious reasons. If anyone else runs into this issue you can setup an alias in docker-compose.yml:

web:
  ...
  networks:
    default:
      aliases:
        - first.lvh.me

For a more flexible solution, you'd have to setup wildcard subdomains in a DNS container. In production, when using a real domain, there shouldn't be an issue.