Created
April 8, 2011 20:43
-
-
Save rafamvc/910698 to your computer and use it in GitHub Desktop.
Example of a mexican class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestObj | |
# All requests coming for #long_background_processing_method will be handled in the background | |
handle_async :method1 | |
# This needs access to be a class method | |
schedule :method2, :every => :day, :at => '12:55am' | |
# The multiple will not allow two #method3 to run at the same time | |
schedule :method3, :every => 30.minutes, :overlap => false | |
# The retroactive will process the summary from every 10 minutes since it ran last time. | |
schedule :method4, :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. | |
schedule :method5, :every => 30.minutes, | |
:retroactive => true, | |
:overlap => false | |
# It will spawn the method my_awesome_daemon as a daemon. | |
# As default, daemons are set not run overlap, but it can be override by setting the number_of_instances of the deamons to run. | |
# 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, :number_of_instances => 2, :interval => 5.seconds | |
# This will use threads instead of forking. | |
daemon :another_daemon, :style => :threaded | |
def method1 | |
TestObj.mockable_method | |
end | |
def method2(*args) | |
TestObj.mockable_method | |
end | |
def method3 | |
TestObj.mockable_method | |
end | |
def method4 | |
TestObj.mockable_method | |
end | |
def method5 | |
TestObj.mockable_method | |
end | |
def my_awesome_daemon | |
TestObj.mockable_method | |
end | |
def another_daemon | |
TestObj.mockable_method | |
end | |
def self.mockable_method | |
end | |
end | |
# ## You can also run: | |
# | |
# a = TestObj.new | |
# | |
# a.delay.method2 | |
# a.delay(:for => 5.minutes).method2 | |
# | |
# | |
# # using run_async | |
# | |
# a = TestObj.new | |
# # Method 2 will not be executed in the current server, but it will push | |
# # this request to the queue and will be processed in the background | |
# a.method1 | |
# | |
# # This will create 4 jobs in the queue | |
# a.method1 | |
# a.method1 | |
# a.method1 | |
# a.method2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment