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

Error handling for missing locked task. #918

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions pybossa/sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,9 +792,17 @@ def get_task_id_and_duration_for_project_user(project_id, user_id):
max_seconds_remaining = float('-inf')
for task_id, task_project_id in zip(user_task_ids, project_ids):
if not task_project_id:
task_project_id = task_repo.get_task(task_id).project_id
save_task_id_project_id(task_id, task_project_id, 2 * TIMEOUT)
if int(task_project_id) == project_id:
task = task_repo.get_task(task_id)
if task:
task_project_id = task.project_id
save_task_id_project_id(task_id, task_project_id, 2 * TIMEOUT)
else:
# No task found for task_id.
current_app.logger.info(
"Project {}, User {}, Task Id {} - task not found in get_task_id_and_duration_for_project_user()."
.format(project_id, user_id, task_id))

if task_project_id and int(task_project_id) == project_id:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional refactor: instead of checking task_project_id on this line, we can add a continue statement after line 802.

seconds_remaining = LockManager.seconds_remaining(user_tasks[task_id])
if seconds_remaining > max_seconds_remaining:
max_seconds_task_id = int(task_id)
Expand Down
18 changes: 18 additions & 0 deletions test/test_locked_sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,24 @@ def test_get_task_id_and_duration_for_project_user_missing(self):
assert get_task_id_project_id_key(task.id).encode() in sentinel.master.keys()
assert task.id == task_id

@with_context
@patch('pybossa.sched.task_repo.get_task')
def test_get_task_id_and_duration_for_project_user_invalid_task_id(self, get_task):
user = UserFactory.create()
project = ProjectFactory.create(owner=user, short_name='egil', name='egil',
description='egil')
task = TaskFactory.create_batch(1, project=project, n_answers=1)[0]
limit = 1
timeout = 100
acquire_locks(task.id, user.id, limit, timeout)

# Simulate invalid task.
get_task.return_value = None
task_id, seconds = get_task_id_and_duration_for_project_user(project.id, user.id)

assert task_id is None
assert seconds == -1

@with_context
def test_tasks_assigned_as_per_user_access_levels_l1(self):
""" Test tasks assigned by locked scheduler are as per access levels set for user, task and project"""
Expand Down
Loading