This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add user record cleanup script (#677)
Add's a new drop_user command that scans the AccessIndex for users that haven't connected in the given month and removes the route records. Closes #645
- Loading branch information
Showing
6 changed files
with
176 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# |
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,39 @@ | ||
import time | ||
|
||
import click | ||
|
||
from autopush.db import ( | ||
get_router_table, | ||
Router, | ||
) | ||
from autopush.metrics import SinkMetrics | ||
|
||
|
||
@click.command() | ||
@click.option('--router_table_name', help="Name of the router table.") | ||
@click.option('--months-ago', default=2, help="Months ago to remove.") | ||
@click.option('--batch_size', default=25, | ||
help="Deletes to run before pausing.") | ||
@click.option('--pause_time', default=1, | ||
help="Seconds to pause between batches.") | ||
def drop_users(router_table_name, months_ago, batch_size, pause_time): | ||
router_table = get_router_table(router_table_name) | ||
router = Router(router_table, SinkMetrics()) | ||
|
||
click.echo("Deleting users with a last_connect %s months ago." | ||
% months_ago) | ||
|
||
count = 0 | ||
for deletes in router.drop_old_users(months_ago): | ||
click.echo("") | ||
count += deletes | ||
if count >= batch_size: | ||
click.echo("Deleted %s user records, pausing for %s seconds." | ||
% pause_time) | ||
time.sleep(pause_time) | ||
count = 0 | ||
click.echo("Finished old user purge.") | ||
|
||
|
||
if __name__ == '__main__': # pragma: nocover | ||
drop_users() |
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