skip to Main Content

what happen to my rails app is very very strange.

To upload the picture that belong to an online article in my app I decide to use carrierwave. All the pictures are in a remote url location and to fetch the image and save them in the server I use a rails worker

ISSUE

When the app save a new feed every article (feedlist) that belongs to this feed is stored in a postgresql db using this worker (Feed has_many Feedlists):

class AddNewFeedWorker

  include Sidekiq::Worker

  sidekiq_options :queue => :default
  sidekiq_options :retry => false #when fail don't repeat

.
.
.

def perform(feed_id)  

feed.entries.each do |entry|  

  entry.published.nil? ? @datafeedlist == Time.now() : @datafeedlist = entry.published
  unless Feedlist.where(:guid => entry.id).exists?

  begin
    @object = LinkThumbnailer.generate(entry.url)
    @img_url = @object.images.last.to_s 
  rescue Exception => exc
    logger.error("Message for the log file: #{exc.message} for the feed id: #{@feed.id}")
    @img_url = entry.image
  end 

  sleep 1

  @f = Feedlist.create!(
    :rssurl       => @feed.rssurl,
    :name         => entry.title,
    :summary      => entry.summary,
    :url          => entry.url,    
    :published_at => @datafeedlist,
    :guid         => entry.id,
    :image        => entry.media_thumbnail_url,
    :remote_article_picture_url => @img_url,
    :content      => entry.content,
    :feed_id      => @feed.id,
    :user_id      => @user.id
  )

  end
end

.
.
.

end # end perform method
end # end worker

this line :remote_article_picture_url => @img_url is a carrierwave notation that fetch from a remote location url a picture and save it in your server.

I said to capistrano to save alle pictures in a shared directory for all releases

my_rails_capistrano_directory/shared/uploads

BUT the app instead to save in this directory the pictures create a new one directory and save there alle the pictures

my_rails_capistrano_directory/releases/20200327071103/uploads

but my current app is in the current release directory

my_rails_capistrano_directory/releases/20200429020251

MY QUESTION IS WHY THAT’S HAPPEN?

To more information you can check the follow code

CAPISTRANO

config/initializers/carrierwave.rb

CarrierWave.configure do |config|
  config.permissions = 0600
  config.directory_permissions = 0700
  config.storage = :file
  config.root = Rails.root
end

config/deploy.rb

append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "vendor/bundle", "uploads"

UPLOADER (I choose to upload in the local machine. The uploads directory is inside the root app but outside from /public dir)

class CategoryLogoUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  storage :file

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  version :middle do
     process resize_to_fit: [400, 300]
  end

  version :thumb do
     process resize_to_fit: [120, 120]
  end

end

MODEL

class Feedlist < ActiveRecord::Base

  mount_uploader :article_picture, CategoryLogoUploader

end

VIEW this code add a new Feed to belong to an user

<%= form_for([@feed.user, @feed]) do |f| %>
  <% if @feed.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@feed.errors.count, "error") %> prohibited this feed from being saved:</h2>

      <ul>
      <% @feed.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

<div class="form-group">
  <%= I18n.t("feed.title") %> <br />
  <%= f.text_field :title %>
</div> <br />

<div class="form-group">
  <%= I18n.t("feed.insert") %><br />
  <%= f.text_field :rssurl, required: true %>
</div> <br />

<div class="form-group">
  <%= f.hidden_field :user_id, :value => current_user.id %>
</div>

<div class="form-group">
  <%= I18n.t("feed.tags_list") %><br />
  <%= f.text_field :tag_list, required: true %>
</div> 

<div class="form-group">    
  <%= f.submit @feed.new_record? ? "#{I18n.t("feed.insert_button")}" : "#{I18n.t("feed.update_button")}", class: "btn btn-info btn-rounded"%>
</div>

<% end %>

CONTROLLER

def create
  @feed 
  if @feed.save                   
    AddNewFeedWorker.perform_async(@feed.id)                                     
    redirect_to root_path
  else
    render 'new', :notice => "something went wrong"
  end
end

FINALLY AT THE END I FIXED THE ISSUE!

simply restart sidekiq and redis and after that everything work like a charm :))

thanks anyway

2

Answers


  1. You need to configure your config.root to the shared directory.

    See “Unable to configure storage path with CarrierWave using config.root #2192“.

    Login or Signup to reply.
  2. I’m not quite sure but seems like the application is not restarted after deployment and still sits in 20200327071103. This is why you get uploaded files to old release dir.

    Another thing I would look is if links are and matching shared dir. For example:

     my_rails_capistrano_directory/releases/20200327071103/uploads ->
     my_rails_capistrano_directory/shared/uploads
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search