BVB Source Codes

rq Show decorators.py Source code

Return Download rq: download decorators.py Source code - Download rq Source code - Type:.py
  1. # -*- coding: utf-8 -*-
  2. from __future__ import (absolute_import, division, print_function,
  3.                         unicode_literals)
  4.  
  5. from functools import wraps
  6.  
  7. from rq.compat import string_types
  8.  
  9. from .defaults import DEFAULT_RESULT_TTL
  10. from .queue import Queue
  11.  
  12.  
  13. class job(object):
  14.     def __init__(self, queue, connection=None, timeout=None,
  15.                  result_ttl=DEFAULT_RESULT_TTL, ttl=None):
  16.         """A decorator that adds a ``delay`` method to the decorated function,
  17.        which in turn creates a RQ job when called. Accepts a required
  18.        ``queue`` argument that can be either a ``Queue`` instance or a string
  19.        denoting the queue name.  For example:
  20.  
  21.            @job(queue='default')
  22.            def simple_add(x, y):
  23.                return x + y
  24.  
  25.            simple_add.delay(1, 2) # Puts simple_add function into queue
  26.        """
  27.         self.queue = queue
  28.         self.connection = connection
  29.         self.timeout = timeout
  30.         self.result_ttl = result_ttl
  31.         self.ttl = ttl
  32.  
  33.     def __call__(self, f):
  34.         @wraps(f)
  35.         def delay(*args, **kwargs):
  36.             if isinstance(self.queue, string_types):
  37.                 queue = Queue(name=self.queue, connection=self.connection)
  38.             else:
  39.                 queue = self.queue
  40.             depends_on = kwargs.pop('depends_on', None)
  41.             return queue.enqueue_call(f, args=args, kwargs=kwargs,
  42.                                       timeout=self.timeout, result_ttl=self.result_ttl,
  43.                                       ttl=self.ttl, depends_on=depends_on)
  44.         f.delay = delay
  45.         return f
  46.  
downloaddecorators.py Source code - Download rq Source code
Related Source Codes/Software:
amazon-dsstne - Deep Scalable Sparse Tensor Network Engine (DSSTNE... 2017-01-08
webpack-demos - a collection of simple demos of Webpack 2017-01-08
Squire - HTML5 rich text editor. Try the demo integration a... 2017-01-08
thor - Thor is a toolkit for building powerful command-li... 2017-01-08
glide - Package Management for Golang h... 2017-01-08
emmet-vim - emmet for vim: http://emmet.io/ ... 2017-01-08
prose - A Content Editor for GitHub. ht... 2017-01-08
sshrc - ring your .bashrc, .vimrc, etc. with you when you ... 2017-01-08
typed.js - A jQuery typing animation script. ... 2017-01-08
find - High-precision indoor positioning framework for mo... 2017-01-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top