generated from opensafely-core/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add task to fetch and store codespaces metrics
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
1 parent
1c05263
commit 54afc27
Showing
2 changed files
with
27 additions
and
0 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,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()) |