Discussion Forums
- Topic List
- Most Recent Posts
- Sign In for more options
Hi guys,
I am trying to create a scheduling algorithm which will run in every 15 mins fetch all the feeds from TechCrunch and store it in my Database.
I was trying to implement this with rufus-scheduler but what's happening is on 15th minute if server gets another request it will terminate the scheduling script and once the script is terminated it will never run on its time...
I have couple of more options on this like backgroundrb, Cronjob, background etc and I tried to implement those but not getting success with anyone of this.
I want my scheduling script to run independently, so that I won't face this termination kind of problem
let me show you some of my code that I have done with rufus-scheduler.
require 'rubygems' require 'rufus/scheduler'
module SchedulerSystem require 'rss/2.0' require 'open-uri'
scheduler = Rufus::Scheduler.start_new
scheduler.every("15m") do
feed_url = "#{RSS_FEED}"
count = 30.to_i
puts("Rss Reader")
open(feed_url) do |http|
response = http.read
result = RSS::Parser.parse(response, false)
puts("Reed Title: #{result.channel.title}")
result.items.each_with_index do |item, i|
puts("#{i+1}. '#{item.link}' and title is: '#{item.title}'") if i< count
end
end
end end
Please let me know how this can be achieved.. I am using windows machine..
Thanks in Advance Regards Puneet
why not using crontab instead?
just append a rake task and call it using cron job
Hi,
I think backgroundrb is the best choise for you. It has the ability to run parallel with the main rails process and you can setup schedules for workers using cronjob like syntax. If u could post what specific problems you run into using backgroundrb may be I can help as I have used bdrb many times for production apps in the past.
regards
darshana
Well, BackgrounDrb is really pretty nice, but don't you think it is too heavy to such a simple requiement?
Just copy your parser codes to a task located in the "lib/tasks" directory and then call rake fetch_feeds RAILS_ENV=production in crontab every 5 minutes.
Well, BackgrounDrb is really pretty nice, but don't you think it is too heavy to such a simple requiement?
Just copy your parser codes to a task located in the "lib/tasks" directory and then call rake fetch_feeds RAILS_ENV=production in crontab every 5 minutes.
of cause..bdrb may be too heavy for this particular task. it's most useful handling cpu heavy code. but more elegant because you can keep all the code and their triggers at one place and commit to the repository. more maintainable I guess
i think backgroundRb is very useful to handle such situation. i show a simple example to implement backgroundRb in the application.
