rq / Flask-RQ2

A Flask extension for RQ.
https://flask-rq2.readthedocs.io/
MIT License
229 stars 48 forks source link

Queuing Python Static Methods. #60

Open reversearrow opened 6 years ago

reversearrow commented 6 years ago

Hello,

I am looking to queue some of the Python @staticmethods. For some reason, I am getting following error when using Python RQ/ Flask-RQ2. Please help.

@staticmethod
@rq.job
def add_request(request):
    db.session.add(request)
    db.session.commit()

@staticmethod
@rq.job
def monitor_request(id):
    job = Job.fetch(id)
    accepted_statues = ['finished','failed']
    while job.status not in accepted_statues:
        time.sleep(1)
    request = Requests.query.filter_by(jobid=job.id).first()
    request.status = job.status
    db.session.add(request)
    db.session.commit()

15:30:06 AttributeError: 'module' object has no attribute 'add_request' Traceback (most recent call last): File "/home/PROD.CAN/rsojshah/netaut/lib/python2.7/site-packages/rq/worker.py", line 789, in perform_job rv = job.perform() File "/home/PROD.CAN/rsojshah/netaut/lib/python2.7/site-packages/rq/job.py", line 573, in perform self._result = self._execute() File "/home/PROD.CAN/rsojshah/netaut/lib/python2.7/site-packages/rq/job.py", line 579, in _execute return self.func(*self.args, *self.kwargs) File "/home/PROD.CAN/rsojshah/netaut/lib/python2.7/site-packages/rq/job.py", line 206, in func return import_attribute(self.func_name) File "/home/PROD.CAN/rsojshah/netaut/lib/python2.7/site-packages/rq/utils.py", line 153, in import_attribute return getattr(module, attribute) AttributeError: 'module' object has no attribute 'add_request' Traceback (most recent call last): File "/home/PROD.CAN/rsojshah/netaut/lib/python2.7/site-packages/rq/worker.py", line 789, in perform_job rv = job.perform() File "/home/PROD.CAN/rsojshah/netaut/lib/python2.7/site-packages/rq/job.py", line 573, in perform self._result = self._execute() File "/home/PROD.CAN/rsojshah/netaut/lib/python2.7/site-packages/rq/job.py", line 579, in _execute return self.func(self.args, **self.kwargs) File "/home/PROD.CAN/rsojshah/netaut/lib/python2.7/site-packages/rq/job.py", line 206, in func return import_attribute(self.func_name) File "/home/PROD.CAN/rsojshah/netaut/lib/python2.7/site-packages/rq/utils.py", line 153, in import_attribute return getattr(module, attribute) AttributeError: 'module' object has no attribute 'add_request' 15:30:06 Moving job to u'failed' queue

jezdez commented 5 years ago

Please provide the whole code example including the class declaration of the static methods.