Skip to content

Commit

Permalink
common/backend/distgit: rename GroupWorkerLimit to HashWorkerLimit
Browse files Browse the repository at this point in the history
The old name caused confusion, see PR#2909.  The new name better
describes what the class actually does.

Even though the dispatcher/worker/limit/etc. logic is supposed to be a
library-like code, at this point we don't know about any other users so
rename like this seems OK.
  • Loading branch information
praiskup committed Sep 22, 2023
1 parent 3793165 commit 3f0536b
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion backend/copr-backend.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
%global tests_version 4
%global tests_tar test-data-copr-backend

%global copr_common_version 0.16.4.dev
%global copr_common_version 0.20.1.dev1

Name: copr-backend
Version: 1.172
Expand Down
4 changes: 2 additions & 2 deletions backend/copr_backend/daemons/build_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BuildDispatcher related classes.
"""

from copr_common.worker_manager import GroupWorkerLimit
from copr_common.worker_manager import HashWorkerLimit
from copr_backend.dispatcher import BackendDispatcher
from copr_backend.rpm_builds import (
ArchitectureWorkerLimit,
Expand Down Expand Up @@ -99,7 +99,7 @@ def __init__(self, backend_opts):
for limit_type in ['sandbox', 'owner']:
max_builders = backend_opts.builds_limits[limit_type]
self.log.info("setting %s limit to %s", limit_type, max_builders)
self.limits.append(GroupWorkerLimit(
self.limits.append(HashWorkerLimit(
lambda x, limit=limit_type: getattr(x, limit),
max_builders,
name=limit_type,
Expand Down
4 changes: 2 additions & 2 deletions backend/copr_backend/rpm_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from copr_common.worker_manager import (
GroupWorkerLimit,
HashWorkerLimit,
WorkerManager,
PredicateWorkerLimit,
)
Expand Down Expand Up @@ -137,7 +137,7 @@ def predicate(x):
super().__init__(predicate, limit, name="arch_{}".format(architecture))


class ArchitectureUserWorkerLimit(GroupWorkerLimit):
class ArchitectureUserWorkerLimit(HashWorkerLimit):
"""
Limit number of machines of specific architecture we give to a single
Copr owner (user or group).
Expand Down
10 changes: 5 additions & 5 deletions backend/tests/test_worker_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# pylint: disable=protected-access

from copr_common.worker_manager import (
GroupWorkerLimit,
HashWorkerLimit,
PredicateWorkerLimit,
StringCounter,
)
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_predicate_worker_limit_sometimes():
assert wl.check(_QT(5)) is False

def test_group_worker_limit():
wl = GroupWorkerLimit(lambda x: x.group, 2)
wl = HashWorkerLimit(lambda x: x.group, 2)
for _ in ["first", "cleared", "cleared"]:
for task in [0, 1, 2]:
wl.worker_added(str(task), _QT(str(task)))
Expand All @@ -115,8 +115,8 @@ def test_worker_limit_info():
limits = [
PredicateWorkerLimit(lambda _: True, 8),
PredicateWorkerLimit(lambda _: True, 8, name='allmatch'),
GroupWorkerLimit(lambda x: x.owner, 4),
GroupWorkerLimit(lambda x: x.sandbox, 2, name='sandbox'),
HashWorkerLimit(lambda x: x.owner, 4),
HashWorkerLimit(lambda x: x.sandbox, 2, name='sandbox'),
ArchitectureWorkerLimit("x86_64", 3),
ArchitectureWorkerLimit("aarch64", 2),
ArchitectureUserWorkerLimit("aarch64", 2),
Expand All @@ -131,7 +131,7 @@ def test_worker_limit_info():
'w:7-fedora-rawhide-x86_64, w:7-fedora-32-x86_64, w:7-fedora-31-x86_64',
"limit info: 'allmatch', matching: w:7, w:7-fedora-rawhide-x86_64, "
'w:7-fedora-32-x86_64, w:7-fedora-31-x86_64',
"limit info: Unnamed 'GroupWorkerLimit' limit, counter: cecil=2, bedrich=2",
"limit info: Unnamed 'HashWorkerLimit' limit, counter: cecil=2, bedrich=2",
"limit info: 'sandbox', counter: sb1=1, sb2=2",
"limit info: 'arch_x86_64', matching: w:7-fedora-rawhide-x86_64, w:7-fedora-32-x86_64, w:7-fedora-31-x86_64",
"limit info: 'arch_aarch64'",
Expand Down
5 changes: 3 additions & 2 deletions common/copr_common/worker_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ def __str__(self):
return ", ".join(items)


class GroupWorkerLimit(WorkerLimit):
class HashWorkerLimit(WorkerLimit):
"""
Assign task to groups, and set maximum number of workers per each group.
Assign tasks to groups per the return value of the HASHER(TASK) method. Set
maximum number of workers **per each such group**.
"""
def __init__(self, hasher, limit, name=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion common/python-copr-common.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
%endif

Name: python-copr-common
Version: 0.20
Version: 0.20.1.dev1
Release: 1%{?dist}
Summary: Python code used by Copr

Expand Down
2 changes: 1 addition & 1 deletion common/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

setup(
name='copr-common',
version="0.20",
version="0.20.1.dev1",
description=__description__,
long_description=long_description,
author=__author__,
Expand Down
2 changes: 1 addition & 1 deletion dist-git/copr-dist-git.spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%global copr_common_version 0.16.4.dev
%global copr_common_version 0.20.1.dev1

Name: copr-dist-git
Version: 0.67
Expand Down
4 changes: 2 additions & 2 deletions dist-git/copr_dist_git/import_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import logging
from copr_common.dispatcher import Dispatcher
from copr_common.worker_manager import GroupWorkerLimit
from copr_common.worker_manager import HashWorkerLimit
from copr_dist_git.importer import Importer, ImportWorkerManager


Expand Down Expand Up @@ -48,7 +48,7 @@ def __init__(self, opts):
for limit_type in ['sandbox', 'owner']:
limit = LIMITS[limit_type]
self.log.info("setting %s limit to %s", limit_type, limit)
self.limits.append(GroupWorkerLimit(
self.limits.append(HashWorkerLimit(
lambda x, limit=limit_type: getattr(x, limit),
limit,
name=limit_type,
Expand Down

0 comments on commit 3f0536b

Please sign in to comment.