Module: Activr::Async
- Defined in:
- lib/activr/async.rb
Overview
Async hooks module
The async hooks module permits to plug any job system to run some part if Activr code asynchronously.
Possible hooks are:
- :route_activity - An activity must me routed by the Dispatcher
- :timeline_handle - An activity must be handled by a timeline
A hook class:
- must implement a `#enqueue` method, used to enqueue the async job
- must call `Activr::Async.<hook_name>` method in the async job
Hook classes to use are specified thanks to the ‘config.async` hash.
When Resque is detected inside a Rails application then defaults hooks are provided out of the box (see the Resque module).
Defined Under Namespace
Modules: Resque
Class Method Summary collapse
-
.hook(name, *args) ⇒ Object
Run hook.
-
.route_activity(activity) ⇒ Object
Hook: route an activity.
-
.timeline_handle(timeline, activity, route) ⇒ Object
Hook: timeline handles an activity thanks to given route.
Class Method Details
.hook(name, *args) ⇒ Object
Run hook
If an async class is defined for that hook name then it is used to process the hook asynchronously, else the hooked code is executed immediately.
58 59 60 61 62 63 64 65 66 |
# File 'lib/activr/async.rb', line 58 def hook(name, *args) if Activr.config.async[name] && (ENV['ACTIVR_FORCE_SYNC'] != 'true') # async Activr.config.async[name].enqueue(*args) else # sync self.__send__(name, *args) end end |
.route_activity(activity) ⇒ Object
Hook: route an activity
76 77 78 |
# File 'lib/activr/async.rb', line 76 def route_activity(activity) Activr.dispatcher.route(activity) end |
.timeline_handle(timeline, activity, route) ⇒ Object
Hook: timeline handles an activity thanks to given route
85 86 87 |
# File 'lib/activr/async.rb', line 85 def timeline_handle(timeline, activity, route) timeline.handle_activity(activity, route) end |