call INCR on version check request

This commit is contained in:
simon 2022-12-22 10:41:33 +07:00
parent 35a90941ff
commit 7d48b7f78f
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 15 additions and 0 deletions

View File

@ -86,3 +86,16 @@ class TaskHandler(RedisBase):
def set_pub(self):
"""set message to pub"""
self.conn.publish(self.key, self.repo_conf.get("gh_repo"))
class VersionCheckCounter(RedisBase):
"""count requests to version check API endpoint"""
def __init__(self):
super().__init__()
self.timestamp = datetime.now().strftime("%Y%m%d")
self.key = f"{self.NAME_SPACE}versioncounter:{self.timestamp}"
def increase(self):
"""increase counter by one"""
self.conn.execute_command("INCR", self.key)

View File

@ -5,6 +5,7 @@ from os import environ
from apscheduler.schedulers.background import BackgroundScheduler
from flask import Flask, render_template, jsonify, request, redirect
from src.api_docker import run_docker_backup
from src.ta_redis import VersionCheckCounter
from src.webhook_docker import DockerHook
from src.webhook_github import GithubBackup, GithubHook
import markdown
@ -44,6 +45,7 @@ def discord_redirect():
def release(release_id):
"""api release"""
result = GithubBackup(release_id).get_tag()
VersionCheckCounter().increase()
return jsonify(result)