Skip to content

Commit

Permalink
Create ProviderETLHandler Abstract class for Workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
amoghjalan committed Apr 9, 2024
1 parent 3346b35 commit da7c060
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytz

from dora.exapi.github import GithubApiService
from dora.service.workflows.sync.etl_provider_handler import ProviderETLHandler
from dora.store.models import UserIdentityProvider
from dora.store.models.code import (
RepoWorkflowProviders,
Expand All @@ -20,7 +21,7 @@
WORKFLOW_PROCESSING_CHUNK_SIZE = 100


class GithubActionsETLHandler:
class GithubActionsETLHandler(ProviderETLHandler):
def __init__(self, org_id: str, github_api_service: GithubApiService):
self.org_id = org_id
self._api: GithubApiService = github_api_service
Expand Down Expand Up @@ -72,11 +73,15 @@ def get_workflow_runs(
)
return []

bookmark.bookmark = self._get_new_bookmark_time_stamp(github_workflow_runs).isoformat()
bookmark.bookmark = self._get_new_bookmark_time_stamp(
github_workflow_runs
).isoformat()

return self._get_db_workflows(github_workflow_runs, str(repo_workflow.id))

def _get_new_bookmark_time_stamp(self, github_workflow_runs: List[Dict]) -> datetime:
def _get_new_bookmark_time_stamp(
self, github_workflow_runs: List[Dict]
) -> datetime:
"""
This method returns the new bookmark timestamp for the workflow runs.
It returns the minimum timestamp of the pending jobs if there are any pending jobs.
Expand Down
36 changes: 36 additions & 0 deletions apiserver/dora/service/workflows/sync/etl_provider_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from abc import ABC, abstractmethod
from typing import List

from dora.store.models.code import (
OrgRepo,
RepoWorkflow,
RepoWorkflowRunsBookmark,
RepoWorkflowRuns,
)


class ProviderETLHandler(ABC):
@abstractmethod
def check_pat_validity(self) -> bool:
"""
This method checks if the PAT is valid.
:return: PAT details
:raises: Exception if PAT is invalid
"""
pass

@abstractmethod
def get_workflow_runs(
self,
org_repo: OrgRepo,
repo_workflow: RepoWorkflow,
bookmark: RepoWorkflowRunsBookmark,
) -> List[RepoWorkflowRuns]:
"""
This method returns all workflow runs of a repo's workflow. After the bookmark date.
:param org_repo: OrgRepo object to get workflow runs for
:param repo_workflow: RepoWorkflow object to get workflow runs for
:param bookmark: Bookmark object to get all workflow runs after this date
:return: List of RepoWorkflowRuns objects
"""
pass

0 comments on commit da7c060

Please sign in to comment.