-
Notifications
You must be signed in to change notification settings - Fork 22
Feat: cache workflow file #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -12,7 +12,9 @@ | |||||
| from typing import Awaitable, Callable, Optional | ||||||
|
|
||||||
| import requests | ||||||
| from github import Github, UnknownObjectException, WorkflowRun | ||||||
| from github import Github, UnknownObjectException | ||||||
| from github.Workflow import Workflow | ||||||
| from github.WorkflowRun import WorkflowRun | ||||||
|
|
||||||
| from libkernelbot.consts import ( | ||||||
| AMD_REQUIREMENTS, | ||||||
|
|
@@ -172,6 +174,9 @@ class GitHubArtifact: | |||||
| public_download_url: str | ||||||
|
|
||||||
|
|
||||||
| _WORKFLOW_FILE_CACHE: dict[str, Workflow] = {} | ||||||
|
|
||||||
|
|
||||||
S1ro1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| class GitHubRun: | ||||||
| def __init__(self, repo: str, token: str, branch: str, workflow_file: str): | ||||||
| gh = Github(token) | ||||||
|
|
@@ -209,6 +214,15 @@ def elapsed_time(self): | |||||
| return None | ||||||
| return datetime.datetime.now(datetime.timezone.utc) - self.start_time | ||||||
|
|
||||||
| async def get_workflow(self) -> Workflow: | ||||||
| if self.workflow_file in _WORKFLOW_FILE_CACHE: | ||||||
| logger.info(f"Returning cached workflow {self.workflow_file}") | ||||||
| return _WORKFLOW_FILE_CACHE[self.workflow_file] | ||||||
| logger.info(f"Fetching workflow {self.workflow_file} from GitHub") | ||||||
| workflow = self.repo.get_workflow(self.workflow_file) | ||||||
|
||||||
| workflow = self.repo.get_workflow(self.workflow_file) | |
| workflow = await asyncio.to_thread(self.repo.get_workflow, self.workflow_file) |
Uh oh!
There was an error while loading. Please reload this page.