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

RDISCROWD-5385: Gracefully handle reserve task category for private instance #765

Merged
merged 1 commit into from
Aug 19, 2022
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
5 changes: 5 additions & 0 deletions pybossa/sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ def get_reserve_task_category_info(reserve_task_config, project_id, timeout, use
if not reserve_task_config:
return sql_filters, category_keys

if current_app.config.get('PRIVATE_INSTANCE'):
current_app.logger.info("Reserve task by category disabled for private instance. project_id %s, reserve_task_config %s",
project_id, str(reserve_task_config))
return sql_filters, category_keys

category = ":".join(["{}:*".format(field) for field in sorted(reserve_task_config)])
lock_manager = LockManager(sentinel.master, timeout)
category_keys = lock_manager.get_task_category_lock(project_id, user_id, category, exclude_user)
Expand Down
7 changes: 7 additions & 0 deletions test/test_reserve_task_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ def test_get_reserve_task_category_info(self, get_task_category_lock):
assert sql_filters == expected_sql_filter and \
category_keys == expected_category_keys, "sql_filters, category_keys must be non empty"

# reserve task disabled for private instance,
with patch.dict(self.flask_app.config, {'PRIVATE_INSTANCE': True}):
sql_filters, category_keys = get_reserve_task_category_info(reserve_task_config, project.id, timeout, owner.id)
assert not sql_filters, "sql_filters must be empty for private instance"
assert not category_keys, "sql_filters must be empty for private instance"


@with_context
def test_acquire_and_release_reserve_task_lock(self):
user = UserFactory.create()
Expand Down