Create app.py
parent
e171ec6146
commit
4a7d5455f0
@ -0,0 +1,13 @@
|
||||
# Dockerfile_flask
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /MyAPI
|
||||
|
||||
COPY requirements.txt requirements.txt
|
||||
RUN pip3 install -r requirements.txt
|
||||
|
||||
COPY MyAPI .
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
CMD ["python3", "app.py"]
|
@ -0,0 +1,4 @@
|
||||
# Dockerfile_grafana
|
||||
FROM grafana/grafana:latest
|
||||
|
||||
# Настройка Grafana, если необходимо
|
@ -0,0 +1,11 @@
|
||||
# Dockerfile_models
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /MyAPI
|
||||
|
||||
COPY requirements.txt requirements.txt
|
||||
RUN pip3 install -r requirements.txt
|
||||
|
||||
COPY MyAPI .
|
||||
|
||||
CMD ["python3", "tasks.py"]
|
@ -0,0 +1,4 @@
|
||||
# Dockerfile_prometheus
|
||||
FROM prom/prometheus:latest
|
||||
|
||||
# Настройка Prometheus, если необходимо
|
@ -0,0 +1,43 @@
|
||||
# app.py
|
||||
from flask import Flask, render_template, request, redirect
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
import importlib.util
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://username:password@postgres:5432/db_name'
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
scheduler = BackgroundScheduler()
|
||||
|
||||
|
||||
class Schedule(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(255))
|
||||
time = db.Column(db.String(255))
|
||||
task = db.Column(db.String(255))
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
schedules = Schedule.query.all()
|
||||
return render_template('index.html', schedules=schedules)
|
||||
|
||||
|
||||
@app.route('/create_schedule', methods=['POST'])
|
||||
def create_schedule():
|
||||
name = request.form['name']
|
||||
time = request.form['time']
|
||||
task = request.form['task']
|
||||
new_schedule = Schedule(name=name, time=time, task=task)
|
||||
db.session.add(new_schedule)
|
||||
db.session.commit()
|
||||
module = importlib.import_module('tasks')
|
||||
func = getattr(module, task)
|
||||
scheduler.add_job(func=func, trigger='cron', hour=time.hour, minute=time.minute)
|
||||
return redirect('/')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
scheduler.start()
|
||||
app.run(host='0.0.0.0', port=5000)
|
@ -0,0 +1,3 @@
|
||||
flask
|
||||
Flask-SQLAlchemy
|
||||
APScheduler
|
Loading…
Reference in New Issue