-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: retrieve availability and save as metadata
- Loading branch information
Showing
7 changed files
with
71 additions
and
1 deletion.
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
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,36 @@ | ||
# -*- coding: utf-8 -*- | ||
from datetime import datetime, timedelta | ||
|
||
from huey import crontab | ||
from huey.contrib.djhuey import periodic_task | ||
|
||
from bd_api.apps.core.models import Metadata | ||
from bd_api.custom.client import BetterStackClient | ||
from bd_api.utils import production_task | ||
|
||
|
||
@periodic_task(crontab(day="1", hour="3", minute="0")) | ||
@production_task | ||
def get_monitor_availability(): | ||
"""Get availability metric and save as metadata""" | ||
|
||
def get_period(): | ||
"""Get last month period as tuple of strings""" | ||
|
||
today = datetime.today() | ||
since = datetime(today.year, today.month - 1, 1) | ||
until = datetime(today.year, today.month, 1) - timedelta(days=1) | ||
return since.strftime("%Y-%m-%d"), until.strftime("%Y-%m-%d") | ||
|
||
since, until = get_period() | ||
client = BetterStackClient() | ||
for monitor in client.get_monitors(): | ||
Metadata.objects.create( | ||
key={ | ||
"since": since, | ||
"until": until, | ||
"monitor_id": monitor["id"], | ||
"monitor_url": monitor["attributes"]["url"], | ||
}, | ||
value=client.get_monitor_summary(monitor["id"], since, until), | ||
) |
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