-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Delete projects when their Github PR is merged (#385)
* feat: add scheduled project cleean up task * style: run lint * test: update tests * chore: bump githubkit * refactor: run delete_merged_project concurrently * chore: add comments
- Loading branch information
1 parent
25f73dc
commit 1304822
Showing
10 changed files
with
203 additions
and
56 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,14 @@ | ||
from ..graph_db import get_current_transaction | ||
|
||
|
||
async def delete_project_nodes(project_id: str): | ||
""" | ||
Remove all nodes for project. | ||
This includes entries, stopwords, synonyms and errors | ||
""" | ||
|
||
query = f""" | ||
MATCH (n:{project_id}) | ||
DETACH DELETE n | ||
""" | ||
await get_current_transaction().run(query) |
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,44 @@ | ||
import asyncio | ||
import contextlib | ||
import logging | ||
|
||
from apscheduler.schedulers.asyncio import AsyncIOScheduler | ||
|
||
from .controllers.project_controller import delete_project, get_projects_by_status | ||
from .github_functions import GithubOperations | ||
from .graph_db import TransactionCtx | ||
from .models.project_models import Project, ProjectStatus | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
async def delete_merged_projects(): | ||
async with TransactionCtx(): | ||
exported_projects = await get_projects_by_status(ProjectStatus.EXPORTED) | ||
results = await asyncio.gather( | ||
*map(delete_merged_project, exported_projects), return_exceptions=True | ||
) | ||
for exception_result in filter(lambda x: x is not None, results): | ||
log.warn(exception_result) | ||
|
||
|
||
async def delete_merged_project(exported_project: Project): | ||
pr_number = exported_project.github_pr_url and exported_project.github_pr_url.rsplit("/", 1)[-1] | ||
if not pr_number: | ||
log.warning(f"PR number not found for project {exported_project.id}") | ||
return | ||
|
||
github_object = GithubOperations(exported_project.taxonomy_name, exported_project.branch_name) | ||
if await github_object.is_pr_merged(int(pr_number)): | ||
await delete_project(exported_project.id) | ||
|
||
|
||
@contextlib.contextmanager | ||
def scheduler_lifespan(): | ||
scheduler = AsyncIOScheduler() | ||
try: | ||
scheduler.add_job(delete_merged_projects, "interval", hours=24) | ||
scheduler.start() | ||
yield | ||
finally: | ||
scheduler.shutdown() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.