Skip to content

Instantly share code, notes, and snippets.

@rafamvc
Created April 8, 2011 20:43
Show Gist options
  • Select an option

  • Save rafamvc/910698 to your computer and use it in GitHub Desktop.

Select an option

Save rafamvc/910698 to your computer and use it in GitHub Desktop.
Example of a mexican class
class TestObj
attr_accessor :meaninful_variable
# All requests coming for #long_background_processing_method will be handled in the background
run_async :long_background_processing_method
# This needs access to be a class method
run :long_consistency_check, :every => :day, :at => '12:55am'
# The multiple will not allow two methods to run at the same time
run :download_updated_tests, :every => 30.minutes, :multiple => false
# The retroactive will process the summary from every 10 minutes since it ran last time.
run :calculate_summary_for_every_10_min, :every => 10.minutes, :retroactive => true
# Same as above, but it will run the the retroactive one after the other,
# rather than all at the same time.
run :calculate_summary_of_summary_for_every_30_min, :every => 30.minutes,
:retroactive => true,
:multiple => false
# It will spawn the method my_awesome_daemon as a daemon.
# As default, daemons are set not run multiples, but it can be override.
# The daemons support some signaling to stop and pause
# The interval is the time between every execution of the method.
# dameons are ran as a forked and detached process, while a run is only a forked process.
daemon :my_awesome_daemon, :multiple => true, :interval => 5.seconds
daemon :another_daemon, :style => (:forked || :threaded)
def initialize
self.meaninful_variable = "something"
end
def slow_method
TestObj.mockable_method
end
def slow_method_with_args(bool_arg)
TestObj.mockable_method(bool_arg)
end
def long_background_processing_method
end
def self.long_consistency_check
end
def self.mockable_method(bool_arg = true)
end
def my_awesome_daemon
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment