SelfDianogse is a library of tasks to diagnose a running system with respect to its dependent external resources. Recently, I did some Rails development and was thinking about how to implement it for the Ruby on Rails framework ? Obvious choice is to make a plugin that on installation adds the SelfDiagnoseController.rb to the application. Because of the scripting nature of Rails framework, putting the configuration in XML (as it is done for Java) is not the Ruby-way. So either use YAML or put the configuration directly into the controller. Let’s investigate the latter.
class SelfdiagnoseController < ActionController
include SelfDiagnose
tasks {
check_database_connection 'mysql'
check_directory_readable '/path/to/dir'
check_log_writeable 'production.log'
check_url_accessable 'http://s3browse.com'
}
end
And the module would be defined as something similar to:
module SelfDiagnose
def tasks
yield if block_given?
end
def check_database_connection(db_name)
# create a new CheckDatabaseConnection task and register it for running
end
def check_log_writeable(log_name)
# create a new CheckLogWriteable task and register it for running
end
end # module
Looking back at this approach, I don’t see the need for having a task registration in the Rails version of SelfDiagnose. I might as well implement the controller like this:
class SelfdiagnoseController < ActionController
include SelfDiagnose
def index
check_database_connection 'mysql'
check_directory_readable '/path/to/dir'
check_log_writeable 'production.log'
check_url_accessable 'http://s3browse.com'
end
end
Then, the index.html.erb will put together a nice report of the results.