Skip to content

Commit 94c4b88

Browse files
Add ReplicationRule.MIN_PRIORITY|MAX_PRIORITY
1 parent 5d69e37 commit 94c4b88

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

b2sdk/replication/setting.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ class ReplicationRule:
2626
name: str
2727
file_name_prefix: str = ''
2828
is_enabled: bool = True
29-
priority: int = 1
29+
priority: int = 128
3030
include_existing_files: bool = False
3131

3232
REPLICATION_RULE_REGEX: ClassVar = re.compile(r'^[a-zA-Z0-9_\-]{1,64}$')
33+
MIN_PRIORITY: ClassVar[int] = 1
34+
MAX_PRIORITY: ClassVar[int] = 2147483647
3335

3436
def __post_init__(self):
3537
if not self.destination_bucket_id:
@@ -38,6 +40,12 @@ def __post_init__(self):
3840
if not self.REPLICATION_RULE_REGEX.match(self.name):
3941
raise ValueError('replication rule name is invalid')
4042

43+
if not (self.MIN_PRIORITY <= self.priority <= self.MAX_PRIORITY):
44+
raise ValueError('priority should be within [%d, %d] interval' % (
45+
self.MIN_PRIORITY,
46+
self.MAX_PRIORITY,
47+
))
48+
4149
def as_dict(self) -> dict:
4250
return {
4351
'destinationBucketId': self.destination_bucket_id,

b2sdk/replication/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
class ReplicationSetupHelper(metaclass=B2TraceMeta):
3434
""" class with various methods that help with repliction management """
3535
PRIORITY_OFFSET: ClassVar[int] = 5 #: how far to to put the new rule from the existing rules
36-
DEFAULT_PRIORITY: ClassVar[int] = 128 #: what priority to set if there are no preexisting rules
37-
MAX_PRIORITY: ClassVar[int] = 255 #: maximum allowed priority of a replication rule
36+
DEFAULT_PRIORITY: ClassVar[int] = ReplicationRule.priority #: what priority to set if there are no preexisting rules
37+
MAX_PRIORITY: ClassVar[int] = ReplicationRule.MAX_PRIORITY #: maximum allowed priority of a replication rule
3838
DEFAULT_SOURCE_CAPABILITIES: ClassVar[Tuple[str, ...]] = (
3939
'readFiles',
4040
'readFileLegalHolds',

0 commit comments

Comments
 (0)