Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
MacHu-GWU committed Jun 5, 2024
1 parent a5a5efe commit 7be3b84
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
41 changes: 34 additions & 7 deletions pynamodb_mate/patterns/status_tracker/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ def is_locked(
def start(
cls,
task_id: str,
allowed_status: T.Optional[T.List[int]] = None,
detailed_error: bool = False,
debug: bool = False,
):
Expand Down Expand Up @@ -781,6 +782,14 @@ def start(
)

try:
is_valid_status = (cls.status == cls.config.pending_status) | (
cls.status == cls.config.failed_status
)
if allowed_status is None:
allowed_status = []
else:
for status in allowed_status:
is_valid_status |= cls.status == status
res = task.update(
actions=[
cls.value.set(
Expand Down Expand Up @@ -809,10 +818,7 @@ def start(
)
)
)
& (
(cls.status == cls.config.pending_status)
| (cls.status == cls.config.failed_status)
)
& is_valid_status
),
)
except UpdateError as e:
Expand Down Expand Up @@ -855,6 +861,27 @@ def start(
)
if debug: # pragma: no cover # pragma: no cover
print("❌ task failed to get lock, because it is ignored.")
elif task_.status not in allowed_status:
if allowed_status:
error = TaskIsNotReadyToStartError(
f"{TaskIsNotReadyToStartError.to_task(cls.config.use_case_id, task_id)} is not ready to start, "
f"the status {task_.status} is not in the allowed status {allowed_status}."
)
if debug:
print(
f"❌ task is not ready to start, "
f"the status {task_.status} is not in the allowed status: {allowed_status}."
)
else:
error = TaskIsNotReadyToStartError.make(
use_case_id=cls.config.use_case_id,
task_id=task_id,
)
if debug:
print(
"❌ task is not ready to start yet, "
"either it is locked or status is not in 'pending' or 'failed'."
)
else: # pragma: no cover
error = NotImplementedError(
f"You found a bug! This error should be handled but not implemented yet, "
Expand All @@ -868,7 +895,7 @@ def start(
if debug: # pragma: no cover
print(
"❌ task is not ready to start yet, "
"either it is locked or status is not in 'pending' or 'failed'."
"either it is locked or status is not in 'pending' or 'failed' or allowed status."
)
else: # pragma: no cover
error = e
Expand Down Expand Up @@ -962,9 +989,9 @@ def _get_status_index(cls, _is_test: bool = False) -> StatusAndUpdateTimeIndex:
"""
Detect the status index object.
"""
if cls._status_and_update_time_index is None: # pragma: no cover
if cls._status_and_update_time_index is None: # pragma: no cover
# just for local unit test, keep it in the source code intentionally
if _is_test: # pragma: no cover
if _is_test: # pragma: no cover
print("call _get_status_index() ...")
for k, v in inspect.getmembers(cls):
if isinstance(v, StatusAndUpdateTimeIndex):
Expand Down
1 change: 1 addition & 0 deletions release-history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Backlog
**Minor Improvements**

- Add ``s3_put_object_kwargs`` parameter to :meth:`pynamodb_mate.patterns.large_attribute.impl.LargeAttributeMixin.create_large_attribute_item` and :meth:`pynamodb_mate.patterns.large_attribute.impl.LargeAttributeMixin.update_large_attribute_item`. So that user can pass additional arguments to the S3 put object requests.
- Allow ``allowed_status`` parameter to :meth:`pynamodb_mate.patterns.status_tracker.impl.BaseStatusTracker.start`. Allow user to specify the allowed status other than "pending" / "failed".

**Bugfixes**

Expand Down

0 comments on commit 7be3b84

Please sign in to comment.