Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert how to execute the url from my...

Replytotopic

how to execute the url from my controller

Posted in Forums : Ask a Rails expert

 
Profile

Authority 0
Posting Rating 16
Sign in to rate this post

My code is as follows
def schedule, require ‘rufus/scheduler’, scheduler =Rufus::Scheduler, p = Rufus::Scheduler.new, p.start, counter=0, p.schedule_every “10s” do *task=’http://localhost:3006/bot/index’??????( i want to schedule this task to run in every 10 sec.) end sleep 21 p.stop end i want to run the url localhost:30006/bot/schedule.so that my task(‘http://localhost:3006/bot/index’) will be run in every 10s.But how can i schedule this task.? please give me any idea.

if i am not understanding through this code ,then the requirement is like

1:- i have this url:-”(‘http://localhost:3006/bot/index’)”. i want to
run this url in every 10sec/period for a specific time.

How can i do that. using rufus-scheduler.because i can not able to setup background.rb in my system.my configuration is:- ruby1.8.6,rails 1.2.3,radrails 1.7.0

please help me in this regard.

 
Me

Authority 37
Posting Rating 100
Sign in to rate this post

I’m not familiar with Rufus:Scheduler. Is it possible for you to set up a cronjob? If yes, I’d suggest setting up a cronjob according to your needs (i.e. running every 10 minutes) that uses curl, wget or whatever to open the URL.

I should probably mention, though, that you shouldn’t have require statements inside method definitions. Put them at the start of the file like this:

require 'rufus/scheduler'

class MyClass < ApplicationController
  def schedule
    # ... whatever
  end
end

PS: pre tags might make your code more readable (like mine). Just use <.pre>code</.pre> (without the periods) around your code.

 
Profile

Authority 0
Posting Rating 16
Sign in to rate this post

Hi Clemens, How i setup cronjob. Is there any Particular gem for this. Would i do it using rufus-scheduler or else to do it any other way. please guide me in this regard. Note:I am working on windows environment.(win-xp)

Thanks for your valuable suggestion.
 
Profile

Authority 12
Posting Rating 95
Sign in to rate this post

Try scheduling it using windows scheduler

Go to control panel -> double click on Scheduled Tasks icon

Then click on Add scheduled Task

Here you can provide the path of the script you want to run and also schedule it to run according to your requirement.

 
Profile

Authority 12
Posting Rating 96
Sign in to rate this post

Please repost your code again, formatted properly.

I’ve never used Rufus::Scheduler but the docs indicate that it can call a method periodically. Look at http://rufus.rubyforge.org/rufus-scheduler/classes/Rufus/Scheduler.html, heading “Cron up to the second”.

No need to browse to a URL of your app periodically when you can just execute the code directly.

 
Profile

Authority 0
Posting Rating 16
Sign in to rate this post

Now it is solved. i just call the http object from another method inside the schedule_every ā€œ10sā€ do *(htttp.get(url)) end .and it works fine.

Replytotopic

Other Recent Topics

Ask a Rails expert : First post, requesting sage perspective

Ask a Rails expert : How to use mephisto

Ask a Rails expert : How to use mephisto

Ask a Rails expert : will_paginate customization problem

Ask a Rails expert : BackgroundRB still wants 'development' environment...?

Ask a Rails expert : activescaffold, sql exception

Ask a Rails expert : Passing non-english chars in query string

Ask a Rails expert : Rails and 2D barcodes

Ask a Rails expert : apache giving proxy error

Ask a Rails expert : Custom Responses w/ 'extra' information...?

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel