-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(data-warehouse): dw heartbeat limits 2 (#19486)
* progress * test * add pause and unpause logic * typing * typing * typing * tested * add log
- Loading branch information
1 parent
78fe1a3
commit 1d2af4e
Showing
10 changed files
with
226 additions
and
21 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
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,38 @@ | ||
from posthog.warehouse.models import ExternalDataJob | ||
from django.db.models import F | ||
|
||
CHUNK_SIZE = 10_000 | ||
|
||
|
||
def limit_paginated_generator(f): | ||
""" | ||
Limits the number of items returned by a paginated generator. | ||
Must wrap a function with args: | ||
team_id: int, | ||
job_id (ExternalDataJob): str | ||
""" | ||
|
||
def wrapped(**kwargs): | ||
job_id = kwargs.pop("job_id") | ||
team_id = kwargs.pop("team_id") | ||
|
||
model = ExternalDataJob.objects.get(id=job_id, team_id=team_id) | ||
gen = f(**kwargs) | ||
count = 0 | ||
for item in gen: | ||
if count >= CHUNK_SIZE: | ||
ExternalDataJob.objects.filter(id=job_id, team_id=team_id).update(rows_synced=F("rows_synced") + count) | ||
count = 0 | ||
|
||
model.refresh_from_db() | ||
|
||
if model.status == ExternalDataJob.Status.CANCELLED: | ||
break | ||
|
||
yield item | ||
count += len(item) | ||
|
||
ExternalDataJob.objects.filter(id=job_id, team_id=team_id).update(rows_synced=F("rows_synced") + count) | ||
|
||
return wrapped |
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
Oops, something went wrong.