jmettraux/rufus-scheduler

error when using with Rails 5

Closed this issue · 12 comments

hi, i try to use rufus in rails 5 ,but there have a problem:

$scheduler.at st.sc_time do
somemethod()
end
$scheduler.join

def somemethod()
files=AutoUploadfile.where(:xmid=>session[:pr_id],:ntype=>0)
end

AutoUploadfile is a model of database table .
when i run the script , it's blocked here : files=AutoUploadfile.where(:xmid=>session[:pr_id],:ntype=>0)
and there is no response ,but i run this code in other program, it's works fine.
so i wanna to kown if it's rufus problem ?

thanks

Hello,

what is the complete error message?

Please give me something like:

NoMethodError: undefined method `[]' for nil:NilClass
./lib/fugit/nat.rb:41:in `parse'
./spec/nat_spec.rb:27:in `block (4 levels) in <top (required)>'
/Users/jmettraux/.gem/ruby/2.2.5/gems/bundler-1.13.5/lib/bundler/cli/exec.rb:74:in `load'
/Users/jmettraux/.gem/ruby/2.2.5/gems/bundler-1.13.5/lib/bundler/cli/exec.rb:74:in `kernel_load'
/Users/jmettraux/.gem/ruby/2.2.5/gems/bundler-1.13.5/lib/bundler/cli/exec.rb:27:in `run'
/Users/jmettraux/.gem/ruby/2.2.5/gems/bundler-1.13.5/lib/bundler/cli.rb:332:in `exec'

Also, what version of Ruby? What operating system? What version of rufus-scheduler?

Thanks in advance.

Also, you are talking about Rails 5. Are you implying it works with Rails 4 or 3 ?

Also, what do you mean by "it's blocked here"? The whole application is blocked?

hi, ruby version 2.2
this is code

          puts "-----------------------"
          puts runtime
          puts st.sc_time
          puts "-----------------------"
          if st.sc_time>runtime then
            $scheduler.at st.sc_time do
              puts '=================='
              puts 'startjob...'
              files=AutoUploadfile.where(:xmid=>session[:pr_id],:ntype=>0)
              puts files.count
              puts '=================='
            end
          end
       end
       $scheduler.join

and there is no error message , just no reponse:

-----------------------
2017-01-04 14:53:36 +0800
2017-01-04 14:54:00 +0800
-----------------------
==================
startjob...

Other question: what Ruby server are you running your Rails 5 on top of? Passenger? Unicorn? Puma? Webrick?

Puma

JRuby or MRI Ruby? What version?

ruby 2.2.4p230 (2015-12-16 revision 53155) [x64-mingw32]
windows 10

files=AutoUploadfile.where(:xmid=>session[:pr_id],:ntype=>0)
this worked fine in other program, but in here it doesn't work ,i wanna kown why .

Remove the

$scheduler.join

line and try again. This line is only for standalone scripts, not for schedulers running inside of the Rails application.

Please tell me what happens (or not) then.

it's worked ! thanks a lot .

You're welcome. Have a nice day!