0

I want use whenever and every 5 min (ex)0,5,10,15,20 ... 55) json parse site and input my database..

and instantly processing script...

config/schedule.rb

every '0,5,10,15,20,25,30,35,40,45,50,55 * * * *' do
 rake "do_something"
end

Rakefile

task :do_something do
        <%a = JSON.parse( open("http://named.com/page/ladder/ajax/result.php").read )%>
         <% b=a['times'] %>

        <% c=a['start_point'] %> 

        <% if c == 'first' %>
        <% c='left' %>
        <% else %>
        <% c= 'right' %>
        <% end %>

        <% d=a['ladder_type'] %>

        <% if d == 'type1' %>
        <% d='3' %>
        <% else %>
        <% d= '4' %>
        <% end %>

        <% e=a['answer'] %>
        <% if e == 'EVEN' %>
        <% e='2' %>
            <% else %>
            <% e= '1' %>
            <% end %>

=begin

I want input this result in db.
=end


    end

and this is schedule script.

a.rb

class Ladder

  include DataMapper::Resource

  property :id, Serial

  property :ladder_type, String 

  property :start_point, String 
  property :times, String 

end

class User

  include DataMapper::Resource

  property :id, Serial

  property :email, String 
  property :password, String 

  property :ladder_type, String 

  property :start_point, String 
  property :times, String 

end

i want input database..

ex) whenever parse and input my database and instantly processing this script.

if u.times == l.times
puts "good"
else
puts "lose"
end

1 Answers1

1

If your rake task is fine, configure whenever to call it every fifth minute using:

every '*/5 * * * *' do
  rake "do_something"
end

But don't forget to run the whenever command on your server to update the crontab file which is responsible for time scheduled jobs. You have to do this from your application working directory, read the README / doc: https://github.com/javan/whenever

maddin2code
  • 1,334
  • 1
  • 14
  • 16