Skip to content

Commit

Permalink
Add task to fetch and store codespaces metrics
Browse files Browse the repository at this point in the history
As the codespaces data will change over time and deleted codespaces
will disappear from the API, we do not drop and recreate the table
each time the task is run as per the other tasks. Instead, calling
the upsert() method ensures the table exists then merges the new
data with the existing.
  • Loading branch information
Jongmassey committed May 30, 2024
1 parent 1c05263 commit 54afc27
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions metrics/github/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ def convert_issue_counts_to_metrics(counts):
}
)
return metrics


def get_codespaces_data(codespaces):
return [vars(c) for c in codespaces]
23 changes: 23 additions & 0 deletions metrics/tasks/codespaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys

import structlog

import metrics.github.github as github
from metrics.timescaledb import db, tables


log = structlog.get_logger()


def main():
log.info("Getting codespaces")
codespaces = github.codespaces(org="opensafely")
log.info(f"Got {len(codespaces)} codespaces")

log.info("Writing data")
db.upsert(tables.GitHubCodespaces, [vars(c) for c in codespaces])
log.info("Written data")


if __name__ == "__main__":
sys.exit(main())

0 comments on commit 54afc27

Please sign in to comment.