-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extra and gifted execution minutes (#1361)
Fixes #1358 - Adds `extraExecMinutes` and `giftedExecMinutes` org quotas, which are not reset monthly but are updateable amounts that carry across months - Adds `quotaUpdate` field to `Organization` to track when quotas were updated with timestamp - Adds `extraExecMinutesAvailable` and `giftedExecMinutesAvailable` fields to `Organization` to help with tracking available time left (includes tested migration to initialize these to 0) - Modifies org backend to track time across multiple categories, using monthlyExecSeconds, then giftedExecSeconds, then extraExecSeconds. All time is also written into crawlExecSeconds, which is now the monthly total and also contains any overage time above the quotas - Updates Dashboard crawling meter to include all types of execution time if `extraExecMinutes` and/or `giftedExecMinutes` are set above 0 - Updates Dashboard Usage History table to include all types of execution time (only displaying columns that have data) - Adds backend nightly test to check handling of quotas and execution time - Includes migration to add new fields and copy crawlExecSeconds to monthlyExecSeconds for previous months Co-authored-by: emma <[email protected]>
- Loading branch information
Showing
13 changed files
with
769 additions
and
111 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
2 changes: 1 addition & 1 deletion
2
backend/btrixcloud/migrations/migration_0022_partial_complete.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
63 changes: 63 additions & 0 deletions
63
backend/btrixcloud/migrations/migration_0023_available_extra_exec_mins.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,63 @@ | ||
""" | ||
Migration 0023 -- Available extra/gifted minutes | ||
""" | ||
from btrixcloud.migrations import BaseMigration | ||
|
||
|
||
MIGRATION_VERSION = "0023" | ||
|
||
|
||
class Migration(BaseMigration): | ||
"""Migration class.""" | ||
|
||
def __init__(self, mdb, migration_version=MIGRATION_VERSION): | ||
super().__init__(mdb, migration_version) | ||
|
||
async def migrate_up(self): | ||
"""Perform migration up. | ||
Add extraExecSecondsAvailable and giftedExecSecondsAvailable to org. | ||
Initialize at 0 to avoid them being None. | ||
Also add monthlyExecSeconds and copy previous crawlExecSeconds values | ||
to it. | ||
""" | ||
# pylint: disable=duplicate-code | ||
mdb_orgs = self.mdb["organizations"] | ||
|
||
query = { | ||
"extraExecSecondsAvailable": None, | ||
"giftedExecSecondsAvailable": None, | ||
} | ||
async for org in mdb_orgs.find(query): | ||
oid = org["_id"] | ||
try: | ||
await mdb_orgs.find_one_and_update( | ||
{"_id": oid}, | ||
{ | ||
"$set": { | ||
"extraExecSecondsAvailable": 0, | ||
"giftedExecSecondsAvailable": 0, | ||
} | ||
}, | ||
) | ||
# pylint: disable=broad-exception-caught | ||
except Exception as err: | ||
print( | ||
f"Error adding exec seconds available fields to org {oid}: {err}", | ||
flush=True, | ||
) | ||
|
||
async for org in mdb_orgs.find({"monthlyExecSeconds": None}): | ||
oid = org["_id"] | ||
try: | ||
await mdb_orgs.update_one( | ||
{"_id": oid}, | ||
[{"$set": {"monthlyExecSeconds": "$crawlExecSeconds"}}], | ||
) | ||
# pylint: disable=broad-exception-caught | ||
except Exception as err: | ||
print( | ||
f"Error copying crawlExecSeconds to monthlyExecSeconds for org {oid}: {err}", | ||
flush=True, | ||
) |
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.