WHENEVER SCHEDULER


Gemfile:-

gem 'whenever', :require => false

For creating scheduler.rb file :- Run that command

wheneverize .


# file: config/schedule.rb

set :environment, "development"
set :output, {:error => "log/cron_error_log.log", :standard => "log/cron_log.log"}


For running the Rake task use:-

every 1.minute do
  rake "shop_products:shop_product_upload_url"
end
For running the Sidekiq Worker :-

every 1.minute do
  runner "UpdateShopProductWorker.perform_async"
end
Rake task:-

lib/tasks/shop.rake

namespace :shop_product do
  task :shop_url => :environment do
    ShopProductUploadUrl.all.each do |csv_data|
       # our operation
    end
  end
end
Worker:-
worker/updateshopproductworker.rb

class UpdateShopProductWorker
    include Sidekiq::Worker
    LOGGER = Logger.new("#{Rails.root}/log/cron_log.log")

    def perform
        update_shop_products
    end

    def update_shop_products
       ShopProductUploadUrl.all.each do |product_url|
         #  operation
       end   
    end
end
Running the whenever in command line:-

bundle exec whenever

then it will generate :-
* * * * * /bin/bash -l -c 'cd /home/yuva/Desktop/02_selectivo_project/selectivo && bin/rails runner -e development '\''UpdateShopProductWorker.perform_async'\'' >> log/cron_log.log 2>> log/cron_error_log.log'
Run on command line then the whenever will run automatically . 


When whenever not working :-

chmod u+x bin/railsbundle exec rake rails:update:bin


http://stackoverflow.com/questions/23297832/weird-rails-error-permission-denied-bin-rails-for-old-rails-apps

Comments

Popular posts from this blog

psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

CARRIERWAVE - UPLOAD ANY MEDIA (AUDIO , VIDEO AND IMAGE ) FILE IN RAILS

SELECT COUNTRY WITH STATE AND IT'S CITIES RAILS

RAILS: UPLOADING PHOTOS VIA AMAZON S3 AND PAPERCLIP (UPLOADING FILES TO S3 IN RUBY WITH PAPERCLIP)

SEARCHING USING AJAX IN RAILS

UPLOAD ANY MEDIA FILE IN RAILS USING PAPERCLIP

UNINITIALIZED CONSTANT PAPERCLIP::STORAGE::S3::AWS

CURL COMMAND ON RUBY ON RAILS

CHECK PASSENGER RUBY PATH