def background_task_method(task):
<EOL>def decorator_fn(fn):<EOL><INDENT>gearman = None<EOL>@inject(config=Config)<EOL>def gearman_connect(config):<EOL><INDENT>if '<STR_LIT>' not in config or '<STR_LIT:host>' not in config['<STR_LIT>'] or '<STR_LIT>' not in config:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>gearman_host = (config['<STR_LIT>']['<STR_LIT:host>'], config['<STR_LIT>']['<STR_LIT:port>']) if config['<STR_LIT>']['<STR_LIT:port>']else config['<STR_LIT>']['<STR_LIT:host>']<EOL>gearman_service = GearmanService({'<STR_LIT>': [gearman_host], '<STR_LIT>': config['<STR_LIT>']})<EOL>gearman_service.set_blocking(False)<EOL>return gearman_service<EOL><DEDENT>def get_gearman_client():<EOL><INDENT>global gearman<EOL>if not gearman:<EOL><INDENT>gearman = gearman_connect()<EOL><DEDENT>return gearman<EOL><DEDENT>@wraps(fn)<EOL>def background_task_decorator(*args, **kwargs):<EOL><INDENT>t = RawTask(task, dict(method=fn.__name__, args=args[<NUM_LIT:1>:], kwargs=kwargs))<EOL>t_result = get_gearman_client().call(t, [JsonTask])<EOL>return t_result.result<EOL><DEDENT>background_task_decorator._background_fn = fn<EOL>return background_task_decorator<EOL><DEDENT>return decorator_fn<EOL>
Decorate an object method as a background task (called with help of
    gearman).

    You have to create a task which will handle the gearman call. The
    method arguments will be encoded as JSON.

    :param task: name of the task
    :type task: str
    :return: decorated function