This module contains a number of helper functions for performing basic Carrot functions, e.g. publish, schedule and consume
Most users should use the functions defined in this module, rather than attempting to subclass the base level objects
carrot.utilities.
create_class_view
(view, decorator)¶Applies a decorator to the dispatch method of a given class based view. Can be chained
Parameters: |
|
---|---|
Return type: | the updated class based view |
carrot.utilities.
create_function_view
(view, decorator)¶Similar to create_class_view()
, but attaches a decorator to a function based view, instead of a class-based
one
Parameters: |
|
---|---|
Return type: | the updated view function |
carrot.utilities.
create_message
(task, priority=0, task_args=(), queue=None, exchange='', routing_key=None, task_kwargs=None)¶Creates a carrot.objects.Message
object without publishing it
The task to execute (as a string or a callable) needs to be supplied. All other arguments are optional :param task: the task to be handled asynchronously. :type task: str or func :param int priority: the priority to be applied to the message when it is published to RabbitMQ
Parameters: |
|
---|---|
Return type: |
carrot.utilities.
create_scheduled_task
(task, interval, queue=None, **kwargs)¶Helper function for creating a carrot.models.ScheduledTask
Parameters: |
|
---|---|
Return type: |
carrot.utilities.
decorate_class_view
(view_class, decorators=None)¶Loop through a list of string paths to decorator functions, and call create_class_view()
for each one
Parameters: |
|
---|---|
Returns: | the class based view with all decorators attached to the dispatch method |
carrot.utilities.
decorate_function_view
(view, decorators=None)¶Similar to decorate_class_view()
, but for function based views
carrot.utilities.
get_host_from_name
(name)¶Gets a host object from a given queue name based on the Django configuration
If no queue name is provided (as may be the case from some callers), this function returns a VirtualHost based on the CARROT.default_broker value.
May raise an exception if the given queue name is not registered in the settings.
Parameters: | name (str) – the name of the queue to lookup. |
---|---|
Return type: | carrot.objects.VirtualHost |
carrot.utilities.
get_mixin
(decorator)¶Helper function that allows dynamic application of decorators to a class-based views
Parameters: | decorator (func) – the decorator to apply to the view |
---|---|
Returns: |
carrot.utilities.
publish_message
(task, *task_args, priority=0, queue=None, exchange='', routing_key=None, **task_kwargs)¶Wrapped for create_message()
, which publishes the task to the queue
This function is the primary method of publishing tasks to a message queue
carrot.utilities.
validate_task
(task)¶Helper function for dealing with task inputs which may either be a callable, or a path to a callable as a string
In case of a string being provided, this function checks whether the import path leads to a valid callable
Otherwise, the callable is converted back into a string (as the carrot.objects.Message
requires a string
input)
This function is used by the following other utility functions:
- create_scheduled_task()
- create_message()
Parameters: | task (str or callable) – a callable or a path to one as a string |
---|---|
Returns: | a validated path to the callable, as a string |