Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assets issue when rendering from background job #18

Open
anero opened this issue Apr 25, 2014 · 3 comments
Open

Assets issue when rendering from background job #18

anero opened this issue Apr 25, 2014 · 3 comments

Comments

@anero
Copy link

anero commented Apr 25, 2014

Hey guys,

We're having some issues not specifically related to render_anywhere but you may be able to shed some light on them.

In our rails 3.2 app, we're using a Sidekiq job for refreshing cache on the background, below is the snippet for the base class and one of the workers:

require 'render_anywhere'

module CacheRenderer
  class Base
    include Sidekiq::Worker
    include RenderAnywhere
  end
end

# ------------------------------------

module CacheRenderer
  class RecentEventRsvps < Base
    #do not enqueue a rendering job more than once for the same petition over a 2 minute period
    sidekiq_options unique: true, unique_job_expiration: 2 * 60

    def perform(event_id)
      event = Event.find(event_id)
      content_to_cache = render(partial: 'shared/attendees_carousel', locals: { ... })
      Rails.cache.write(['recent_event_rsvps', event.cache_key], content_to_cache)
    end
  end
end

Now this is rendered just fine in development, where assets are not precompiled, but in other environments a AssetNotPrecompiledError exception is risen for an image referenced from an image_tag. Doing some debugging we found that Rails.application.config.assets.digests is nil when the job is ran. Assets are synced to S3 using asset_sync.
Have you ever seen this kind of issues? Do you know if we need to perform any manual initialization for sprockets on the sidekiq job?

Thanks in advance,
Diego.

@robb1e
Copy link
Contributor

robb1e commented Apr 27, 2014

Is your Sidekiq process loading all of Rails, or just some portions of your application? If it's loading all of Rails it should load everything it needs. If it's a portion, there may be some initializers you need to include.

I've also seen issues before if there's an asset host, say if a CDN is being used. Are you using one?

@anero
Copy link
Author

anero commented Apr 29, 2014

We're loading the full app; but the issue might be on the CDN (Cloudfront), is there an extra step required to reference the assets on a different host?

Another thing that I realized it may be important is that the sidekiq workers are running on a separated server which doesn't run assets precompilation (the assets are precompiled on the web app servers and uploaded to S3 through the asset_sync gem).

@robb1e
Copy link
Contributor

robb1e commented May 14, 2014

I think you'll want config.assets.compile = false in your config, and also set the CDN config.action_controller.asset_host = "cdn.domain.com". Then it shouldn't even try to compile it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants