Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

severe issue: Getting 415 HTTP code when retrieving task #5

Open
baibinghere opened this issue Aug 3, 2017 · 1 comment
Open

severe issue: Getting 415 HTTP code when retrieving task #5

baibinghere opened this issue Aug 3, 2017 · 1 comment

Comments

@baibinghere
Copy link

After installing this plugin, I'm not able to perform the following operation:

GET http://192.168.116.135:5000/api/project/1/newtask?offset=0&_=1501769112591 415 (UNSUPPORTED MEDIA TYPE)

Root Cause Analysis:
As I have checked, the error is thrown at:
api/init.py:188

    task = sched.new_task(project_id, project.info.get('sched'),
                          user_id,
                          user_ip,
                          external_uid,
                          offset,
                          limit,
                          orderby=orderby,
                          desc=desc)

Throwing below error message:

wrapper() takes at most 5 arguments (9 given)

Prototype of new_task in sched.py:

def new_task(project_id, sched, user_id=None, user_ip=None,
             external_uid=None, offset=0, limit=1, orderby='priority_0', desc=True):

In the plugin, the new_task function has been reassigned:

        sched.new_task = with_random_scheduler(sched.new_task)

But with_random_scheduler's wrapper only takes 5 arguments:

def with_random_scheduler(f):
    @wraps(f)
    def wrapper(project_id, sched, user_id=None, user_ip=None, offset=0):
        if sched == SCHEDULER_NAME:
            return get_random_task(project_id, user_id, user_ip, offset=offset)
        return f(project_id, sched, user_id=user_id, user_ip=user_ip, offset=offset)
    return wrapper

Basically, I made the below changes to make it work, I'm sure it's just a workaround:

--- pybossa/plugins/random-scheduler/__init__.py	(revision )
+++ pybossa/plugins/random-scheduler/__init__.py	(revision )
@@ -16,14 +16,15 @@
     """Return a random task for the user."""
     project = project_repo.get(project_id)
     if project and len(project.tasks) > 0:
-        return random.choice(project.tasks)
+        return [random.choice(project.tasks)]
     else:
-        return None
+        return []
 
 
 def with_random_scheduler(f):
     @wraps(f)
-    def wrapper(project_id, sched, user_id=None, user_ip=None, offset=0):
+    def wrapper(project_id, sched, user_id=None, user_ip=None,
+                external_uid=None, offset=0, limit=1, orderby='priority_0', desc=True):
         if sched == SCHEDULER_NAME:
             return get_random_task(project_id, user_id, user_ip, offset=offset)
         return f(project_id, sched, user_id=user_id, user_ip=user_ip, offset=offset)
@ghaimov
Copy link

ghaimov commented Nov 4, 2018

Hey,
Thanks for the example!

Also, In order to actually get only the tasks that are ongoing, I added another filter (another workaround) to handle this:

def get_random_task(project_id, user_id=None, user_ip=None,n_answers=30, offset=0):
    """Return a random task for the user."""
    project = project_repo.get(project_id)
    if project and len(project.tasks) > 0:
        ongoing_tasks = [task for task in project.tasks if task.state=='ongoing']
        return [random.choice(ongoing_tasks)]
    else:
        return []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants