from rq.decorators import job

from .queues import get_queue


class job(job):
    """
    The same as RQ's job decorator, but it works automatically works out
    the ``connection`` argument from RQ_QUEUES.
    """

    def __init__(self, queue, connection=None, *args, **kwargs):        
        if isinstance(queue, basestring):
            try:
                queue = get_queue(queue)
                if connection is None:
                    connection = queue.connection
            except KeyError:
                pass
        super(job, self).__init__(queue, connection, *args, **kwargs)
from rq.decorators import job as _rq_job

from .queues import get_queue


def job(func_or_queue, connection=None, *args, **kwargs):
    """
    The same as RQ's job decorator, but it works automatically works out
    the ``connection`` argument from RQ_QUEUES.

    And also, it allows simplified ``@job`` syntax to put job into
    default queue.
    """
    if callable(func_or_queue):
        func = func_or_queue
        queue = 'default'
    else:
        func = None
        queue = func_or_queue

    if isinstance(queue, basestring):
        try:
            queue = get_queue(queue)
            if connection is None:
                connection = queue.connection
        except KeyError:
            pass

    decorator = _rq_job(queue, connection=connection, *args, **kwargs)
    if func:
        return decorator(func)
    return decorator


Allow simple syntax for `job` decorator.
Allow simple syntax for `job` decorator.

It is nice to use simple syntax:

    @job
    def some_func():
        pass

in cases, when you have only 'default' queue.

- from rq.decorators import job
+ from rq.decorators import job as _rq_job
  
  from .queues import get_queue
  
  
- class job(job):
+ def job(func_or_queue, connection=None, *args, **kwargs):
      """
      The same as RQ's job decorator, but it works automatically works out
      the ``connection`` argument from RQ_QUEUES.
+ 
+     And also, it allows simplified ``@job`` syntax to put job into
+     default queue.
      """
+     if callable(func_or_queue):
+         func = func_or_queue
+         queue = 'default'
+     else:
+         func = None
+         queue = func_or_queue
  
-     def __init__(self, queue, connection=None, *args, **kwargs):        
-         if isinstance(queue, basestring):
+     if isinstance(queue, basestring):
-             try:
+         try:
-                 queue = get_queue(queue)
+             queue = get_queue(queue)
-                 if connection is None:
+             if connection is None:
-                     connection = queue.connection
+                 connection = queue.connection
-             except KeyError:
+         except KeyError:
-                 pass
+             pass
-         super(job, self).__init__(queue, connection, *args, **kwargs)
+ 
+     decorator = _rq_job(queue, connection=connection, *args, **kwargs)
+     if func:
+         return decorator(func)
+     return decorator
+ 
+ 
Allow simple syntax for `job` decorator.
## Code Before:
from rq.decorators import job

from .queues import get_queue


class job(job):
    """
    The same as RQ's job decorator, but it works automatically works out
    the ``connection`` argument from RQ_QUEUES.
    """

    def __init__(self, queue, connection=None, *args, **kwargs):        
        if isinstance(queue, basestring):
            try:
                queue = get_queue(queue)
                if connection is None:
                    connection = queue.connection
            except KeyError:
                pass
        super(job, self).__init__(queue, connection, *args, **kwargs)
## Instruction:
Allow simple syntax for `job` decorator.
## Code After:
from rq.decorators import job as _rq_job

from .queues import get_queue


def job(func_or_queue, connection=None, *args, **kwargs):
    """
    The same as RQ's job decorator, but it works automatically works out
    the ``connection`` argument from RQ_QUEUES.

    And also, it allows simplified ``@job`` syntax to put job into
    default queue.
    """
    if callable(func_or_queue):
        func = func_or_queue
        queue = 'default'
    else:
        func = None
        queue = func_or_queue

    if isinstance(queue, basestring):
        try:
            queue = get_queue(queue)
            if connection is None:
                connection = queue.connection
        except KeyError:
            pass

    decorator = _rq_job(queue, connection=connection, *args, **kwargs)
    if func:
        return decorator(func)
    return decorator

