I’m using Sphinx and Ultrasphinx for the search engine on one of my projects. I have been struggling with ways to automated the indexing of the database as the commands are rake commands on the command line. Turns out that rufus-scheduler is an excellent solution to this issue. If you allow the scheduler access to the rake file, it is as simple as this schedule below – it is designed to reindex every 90 minutes. I have chose to use the ultrasphinx:bootstrap command because it also has the God like quality of making sure the search server is running at all times.
config/initializers/task_schedule.rb
require 'rake'
require 'rufus/scheduler'
load File.join( RAILS_ROOT, 'Rakefile')
scheduler = Rufus::Scheduler.start_new
scheduler.every("90m") do
Rake::Task["ultrasphinx:bootstrap"].invoke
end
One thing I liked about rspec was the ability to define tests that you had not yet written. That way you could remind yourself when running the test suite that there are things still to do. Previously in Shoulda, I have been writing these kinds of tests in all caps and using “assert false” to trigger failure and remind me of future work. Turns out there is a nifty way to do it with Shoulda. (I should have guessed there would be!)
should_eventually "do something"
#or just leave off the block
should "do something"
Thanks to BlenderBox for bringing this to my attention while researching Shoulda integration testing.
function mysqlTimeStampToDate(timestamp) {
//function parses mysql datetime string and returns javascript Date object
//input has to be in this format: 2007-06-05 15:26:02
var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
}
Source: http://snippets.dzone.com/posts/show/4132