Skip to content

Queuing Python Static Methods. #60

Open

Description

@reversearrow

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

Activity

  1. jezdez commented on Sep 19, 2018

    @jezdez
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions