Cron create error with rails runner
I have rails app, but I have problem with scheduled work.
My crontable(by whenever):
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58
* * * * /bin/bash -l -c 'cd
/home/oliver/apps/parovanie/releases/20130918135145 && bin/rails runner -e
production '\''SheduleRunner.check_mail'\'' >> log/cron_log.log 2>&1'
My ruby(rails) class:
require 'pairing'
class SheduleRunner
def self.check_mail
Mailman.config.logger = CustomLogger.new("log/mailman.log")
Mailman.config.imap = {
server: Figaro.env.email_host, port: Figaro.env.email_imap_port,
ssl: false,
username: Figaro.env.email_name,
password: Figaro.env.email_password
}
Mailman.config.poll_interval = 0
Mailman::Application.run do
from Figaro.env.pairing_from do
begin
if message.has_attachments?
if message.attachments[0].filename.include?('.ZIP')
p = Pairing.new
Mailman.logger.info("Email receive with attachment:
#{message.attachments[0].filename}")
p.load_attachment_from_email(message.attachments[0].filename,message.attachments[0].body.decoded)
Mailman.logger.info("Email processed.")
end
end
rescue Exception => e
Mailman.logger.error "Exception occurred while receiving
message:\n#{message}"
Mailman.logger.error [e, *e.backtrace].join("\n")
end
end
default do
Mailman.logger.info("Default route: #{message.from} -
attachments:#{message.has_attachments?}")
end
end
nil
end
end
My cron log:
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands/runner.rb:53:in
`eval': undefined method `each' for nil:NilClass (NoMethodError)
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/bundler/gems/mailman-bb897b1d81e2/lib/mailman/route.rb:29:in
`block in match!'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/bundler/gems/mailman-bb897b1d81e2/lib/mailman/route.rb:28:in
`each'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/bundler/gems/mailman-bb897b1d81e2/lib/mailman/route.rb:28:in
`match!'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/bundler/gems/mailman-bb897b1d81e2/lib/mailman/router.rb:48:in
`block in route'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/bundler/gems/mailman-bb897b1d81e2/lib/mailman/router.rb:47:in
`each'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/bundler/gems/mailman-bb897b1d81e2/lib/mailman/router.rb:47:in
`route'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/bundler/gems/mailman-bb897b1d81e2/lib/mailman/message_processor.rb:23:in
`block in process'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/bundler/gems/mailman-bb897b1d81e2/lib/mailman/middleware.rb:33:in
`call'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/bundler/gems/mailman-bb897b1d81e2/lib/mailman/middleware.rb:33:in
`block in run'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/bundler/gems/mailman-bb897b1d81e2/lib/mailman/middleware.rb:38:in
`call'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/bundler/gems/mailman-bb897b1d81e2/lib/mailman/middleware.rb:38:in
`run'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/bundler/gems/mailman-bb897b1d81e2/lib/mailman/message_processor.rb:22:in
`process'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/bundler/gems/mailman-bb897b1d81e2/lib/mailman/application.rb:71:in
`run'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/bundler/gems/mailman-bb897b1d81e2/lib/mailman/application.rb:11:in
`run'
from
/home/oliver/apps/parovanie/releases/20130918135145/lib/sheduler_runner.rb:19:in
`check_mail'
from (eval):1:in `<top (required)>'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands/runner.rb:53:in
`eval'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands/runner.rb:53:in
`<top (required)>'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:86:in
`require'
from
/home/oliver/apps/parovanie/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:86:in
`<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
When I run code from crontab in command line(via ssh) :
oliver@rubypro:~$ /bin/bash -l -c 'cd
/home/oliver/apps/parovanie/releases/20130918135145 && bin/rails runner -e
production '\''SheduleRunner.check_mail'\'' >> log/cron_log.log 2>&1'
It worked.
Figaro works without problems, I checked it.
Cron use right ruby(rvm). I checked it with cron jobs: puts RbConfig.ruby
When I clean my code and check_mail method looks like:
def self.check_mail
Mailman.config.logger = CustomLogger.new("log/mailman.log")
Mailman.config.imap = {
server: Figaro.env.email_host, port: Figaro.env.email_imap_port,
ssl: false,
username: Figaro.env.email_name,
password: Figaro.env.email_password
}
Mailman.config.poll_interval = 0
Mailman::Application.run do
end
nil
end
I have no errors, but I need read email from email and others.
I don't know where can be problem. Anybody help? PS:Sorry for my english.
No comments:
Post a Comment