Pergunta

I am using Whenever gem for cron task.

This is my schedule.rb file"

set :output, "#{path}/log/cron.log"
set :environment, 'develop'

every 2.minutes do
  runner "User.say_hello"
end

but it writes to the crontab with extra back-slashes and it is not working

script/rails runner -e develop '\''User.say_hello'\''

But It should be like that?

script/rails runner -e develop 'User.say_hello'

UPDATE

This is my class method in User class

def self.say_hello
   Mailer.cooperation("current_user").deliver!
end

It raises this error

You did not specify how you would like Rails to report deprecation notices for your develop environment, please set config.active_support.deprecation to :log, :notify or :stderr at config/environments/develop.rb
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p448@socposts/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
        from /home/sunloverz/.rvm/gems/ruby-1.9.3-p448@socposts/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
        from /home/sunloverz/.rvm/gems/ruby-1.9.3-p448@socposts/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'

I have already added

  config.active_support.deprecation = :log

In the cron log it prints and doesn't send mail,
but Mailer.cooperation("current_user").deliver! is sending mails from rails console

Database.yml

development:
  adapter: postgresql
  encoding: utf8
  reconnect: false
  database: project_db
  pool: 5
  username: root
  password: lkjsdEEdfd
  host: localhost
Foi útil?

Solução

The problem is that you're using different names for the same environment:

In your database.yml you're calling it development

whereas you're running your whenever task with environment called develop

they have to match.

It's normal everything is working fine til now, because the default name Rails uses is development, so if you're not specifying any environment when migrating, it'll use development by default. But you're running the whenever task with develop environment, which has not actually any db associated.

hope it helps.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top