'The @app.task(interval) decorator will call the given function repeatedly (in a thread).
For example, this can be used to commit a Database.batch periodically,
instead of executing and committing to a Database during each request.'

def task(self, interval=MINUTE):

    def decorator(handler):
        (_, _, args, kwargs) = define(handler)
        def wrapper():
            m = cp.process.plugins.ThreadManager(cp.engine)
            m.acquire_thread()
            return handler(**dict(((k, v) for (k, v) in g.items() if (k in kwargs))))
        p = cp.process.plugins.BackgroundTask(interval, wrapper)
        p.start()
        return handler
    return decorator
