-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67aaaad
commit 5b2bd20
Showing
9 changed files
with
118 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/hope_dedup_engine/apps/api/migrations/0011_dedupjob_progress.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0.7 on 2024-11-04 22:42 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("api", "0010_dedupjob"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="dedupjob", | ||
name="progress", | ||
field=models.IntegerField(default=0), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from collections.abc import Callable, Generator | ||
from functools import partial | ||
|
||
STEP = 10 | ||
|
||
|
||
def callback_filter( | ||
callback: Callable[[int], None], step: int | ||
) -> Callable[[int], None]: | ||
previous_callback_value = -1 | ||
|
||
def update(progress: int) -> None: | ||
nonlocal previous_callback_value | ||
if (callback_value := progress // step * step) != previous_callback_value: | ||
callback(callback_value) | ||
previous_callback_value = callback_value | ||
|
||
return update | ||
|
||
|
||
def track_progress( | ||
callback: Callable[[int], None], send_zero: bool = True | ||
) -> Callable[[int], None]: | ||
update = callback_filter(callback, STEP) | ||
|
||
if send_zero: | ||
update(0) | ||
|
||
return update | ||
|
||
|
||
def track_progress_multi( | ||
callback: Callable[[int], None] | ||
) -> Generator[Callable[[int], None], None, None]: | ||
progress = [] | ||
|
||
update = callback_filter(callback, STEP) | ||
|
||
def individual_callback(value: int, index: int) -> None: | ||
progress[index] = value | ||
update(sum(progress) // len(progress)) | ||
|
||
send_zero = True | ||
while True: | ||
progress.append(0) | ||
yield track_progress( | ||
callback=partial(individual_callback, index=len(progress) - 1), | ||
send_zero=send_zero, | ||
) | ||
send_zero = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters