Skip to content

Assets issue when rendering from background job #18

@anero

Description

@anero

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions