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

Popular posts from this blog

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

SELECT COUNTRY WITH STATE AND IT'S CITIES RAILS

CREATE API FOR USER SIGN UP, LOGIN AND CREATE PUBLISHER WITH CURRENT USER

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

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

DEPLOYING PROJECT USING CAPISTRANO (CAPISTRANO IN RAILS)

GENERATE PDF FILE IN RAILS

HOW TO CALL RAILS API FROM SIMPLE HTML PAGE.