Skip to content

Commit d195fcd

Browse files
committed
Refactor default replication rule priority
1 parent 94c4b88 commit d195fcd

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

b2sdk/replication/setting.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ class ReplicationRule:
2222
prefix and rule name.
2323
"""
2424

25+
DEFAULT_PRIORITY: ClassVar[int] = 128
26+
2527
destination_bucket_id: str
2628
name: str
2729
file_name_prefix: str = ''
2830
is_enabled: bool = True
29-
priority: int = 128
31+
priority: int = DEFAULT_PRIORITY
3032
include_existing_files: bool = False
3133

3234
REPLICATION_RULE_REGEX: ClassVar = re.compile(r'^[a-zA-Z0-9_\-]{1,64}$')
@@ -41,10 +43,12 @@ def __post_init__(self):
4143
raise ValueError('replication rule name is invalid')
4244

4345
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-
))
46+
raise ValueError(
47+
'priority should be within [%d, %d] interval' % (
48+
self.MIN_PRIORITY,
49+
self.MAX_PRIORITY,
50+
)
51+
)
4852

4953
def as_dict(self) -> dict:
5054
return {

b2sdk/replication/setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@
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] = 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
36+
DEFAULT_PRIORITY: ClassVar[
37+
int
38+
] = ReplicationRule.DEFAULT_PRIORITY #: what priority to set if there are no preexisting rules
39+
MAX_PRIORITY: ClassVar[
40+
int] = ReplicationRule.MAX_PRIORITY #: maximum allowed priority of a replication rule
3841
DEFAULT_SOURCE_CAPABILITIES: ClassVar[Tuple[str, ...]] = (
3942
'readFiles',
4043
'readFileLegalHolds',

test/integration/test_raw_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def raw_api_test_helper(raw_api, should_cleanup_old_buckets):
201201
"fileNamePrefix": "",
202202
"includeExistingFiles": True,
203203
"isEnabled": True,
204-
"priority": 1,
204+
"priority": 128,
205205
"replicationRuleName": "test-rule"
206206
},
207207
],

0 commit comments

Comments
 (0)