mirror of
https://github.com/tubearchivist/tubearchivist-server.git
synced 2024-11-21 19:30:12 +00:00
add scheduled backup of docker stats to pg
This commit is contained in:
parent
7fdb73a452
commit
0c1c68a718
3
env/tubearchivist.sample.env
vendored
3
env/tubearchivist.sample.env
vendored
@ -1,6 +1,9 @@
|
||||
TZ=America/New_York
|
||||
REDDIT_HOOK_URL=https://discordapp.com/api/webhooks/000000000000000000/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
ROADMAP_HOOK_URL=https://discordapp.com/api/webhooks/000000000000000000/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
DOCKER_UNSTABLE_HOOK_URL=https://discordapp.com/api/webhooks/000000000000000000/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
GITHUB_RELEASE_HOOK_URL=https://discord.com/api/webhooks/000000000000000000/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
NOTIFICATION_TEST_HOOK_URL=https://discord.com/api/webhooks/000000000000000000/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
|
||||
GH_HOOK_SECRET=xxxxxxxxxxxxxxxxxxxxxxxx
|
||||
DOCKER_HOOK_SECRET=yyyyyyyyyyyyyyyyyyyyyyyy
|
@ -1,7 +1,8 @@
|
||||
APScheduler==3.9.1
|
||||
flask==2.1.2
|
||||
ipython==8.4.0
|
||||
markdown==3.3.7
|
||||
psycopg2==2.9.3
|
||||
redis==4.3.1
|
||||
redis==4.3.3
|
||||
requests==2.27.1
|
||||
uWSGI==2.0.20
|
||||
|
@ -19,9 +19,11 @@ class DockerBackup:
|
||||
|
||||
def run_backup(self):
|
||||
"""public method to run"""
|
||||
print("start hourly docker stats backup")
|
||||
self._get_image_stats()
|
||||
self._build_query()
|
||||
self._insert_line()
|
||||
print("completed hourly docker stats backup")
|
||||
|
||||
def _get_image_stats(self):
|
||||
"""return dict for image"""
|
||||
@ -58,3 +60,8 @@ class DockerBackup:
|
||||
handler = DatabaseConnect()
|
||||
handler.db_execute(self.query)
|
||||
handler.db_close()
|
||||
|
||||
|
||||
def run_docker_backup():
|
||||
"""hourly task to store docker stats"""
|
||||
DockerBackup().run_backup()
|
||||
|
@ -1,12 +1,27 @@
|
||||
"""holds all views and api endpoints"""
|
||||
|
||||
from os import environ
|
||||
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from flask import Flask, render_template, jsonify, request
|
||||
from src.api_docker import run_docker_backup
|
||||
from src.webhook_docker import DockerHook
|
||||
from src.webhook_github import GithubBackup, GithubHook
|
||||
import markdown
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
scheduler = BackgroundScheduler(timezone=environ.get("TZ"))
|
||||
scheduler.add_job(
|
||||
run_docker_backup,
|
||||
trigger="cron",
|
||||
day="*",
|
||||
hour="*",
|
||||
minute="2",
|
||||
name="docker_backup",
|
||||
)
|
||||
scheduler.start()
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
|
Loading…
Reference in New Issue
Block a user