Skip to content
Snippets Groups Projects
Commit e8802537 authored by Andreas Valder's avatar Andreas Valder
Browse files

moved scheduler related stuff to scheduler.py, moved some more parts to template_helper.py

parent 570430ef
No related branches found
No related tags found
No related merge requests found
from server import *
import threading
import sched
scheduler = sched.scheduler()
def run_scheduler():
time.sleep(1) # UWSGI does weird things on startup
while True:
scheduler.run()
time.sleep(10)
def sched_func(delay, priority=0, firstdelay=None, args=[], kargs={}):
if firstdelay == None:
firstdelay = random.randint(1, 120)
def wrapper(func):
def sched_wrapper():
with app.test_request_context():
try:
func(*args, **kargs)
except Exception:
traceback.print_exc()
scheduler.enter(delay, priority, sched_wrapper)
scheduler.enter(firstdelay, priority, sched_wrapper)
return func
return wrapper
threading.Thread(target=run_scheduler, daemon=True).start()
...@@ -2,12 +2,10 @@ from flask import Flask, g, request, url_for, redirect, session, render_template ...@@ -2,12 +2,10 @@ from flask import Flask, g, request, url_for, redirect, session, render_template
from werkzeug.routing import Rule from werkzeug.routing import Rule
from functools import wraps from functools import wraps
from datetime import date, timedelta, datetime, time, MINYEAR from datetime import date, timedelta, datetime, time, MINYEAR
import threading
import os import os
import sys import sys
import hashlib import hashlib
import random import random
import sched
import traceback import traceback
import string import string
from socket import gethostname from socket import gethostname
...@@ -16,46 +14,12 @@ import math ...@@ -16,46 +14,12 @@ import math
import locale import locale
import base64 import base64
import json import json
import time
locale.setlocale(locale.LC_ALL, 'de_DE.utf8') locale.setlocale(locale.LC_ALL, 'de_DE.utf8')
app = Flask(__name__) app = Flask(__name__)
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
app.add_template_global(random.randint, name='randint')
app.add_template_global(datetime, name='datetime')
app.add_template_global(timedelta, name='timedelta')
app.add_template_global(gethostname, name='gethostname')
app.add_template_global(min, name='min')
app.add_template_global(max, name='max')
scheduler = sched.scheduler()
def run_scheduler():
import time
time.sleep(1) # UWSGI does weird things on startup
while True:
scheduler.run()
time.sleep(10)
def sched_func(delay, priority=0, firstdelay=None, args=[], kargs={}):
if firstdelay == None:
firstdelay = random.randint(1, 120)
def wrapper(func):
def sched_wrapper():
with app.test_request_context():
try:
func(*args, **kargs)
except Exception:
traceback.print_exc()
scheduler.enter(delay, priority, sched_wrapper)
scheduler.enter(firstdelay, priority, sched_wrapper)
return func
return wrapper
threading.Thread(target=run_scheduler, daemon=True).start()
config = app.config config = app.config
config.from_pyfile('config.py.example', silent=True) config.from_pyfile('config.py.example', silent=True)
if sys.argv[0].endswith('run.py'): if sys.argv[0].endswith('run.py'):
...@@ -65,17 +29,13 @@ config.from_pyfile('config.py', silent=True) ...@@ -65,17 +29,13 @@ config.from_pyfile('config.py', silent=True)
if config['DEBUG']: if config['DEBUG']:
app.jinja_env.auto_reload = True app.jinja_env.auto_reload = True
# get git commit
import subprocess
output = subprocess.check_output(['git', "log", "-g", "-1", "--pretty=%H # %h # %d # %s"]).decode('UTF-8').split('#', 3)
app.jinja_env.globals['gitversion'] = { 'hash': output[1], 'longhash': output[0], 'branch': output[2], 'msg': output[3] }
if not config.get('SECRET_KEY', None): if not config.get('SECRET_KEY', None):
config['SECRET_KEY'] = os.urandom(24) config['SECRET_KEY'] = os.urandom(24)
from db import query, modify, show, searchquery from db import query, modify, show, searchquery
from ldap import ldapauth from ldap import ldapauth
from legacy import legacy_index from legacy import legacy_index
from scheduler import sched_func
mod_endpoints = [] mod_endpoints = []
......
from server import * from server import *
import subprocess
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
app.add_template_global(random.randint, name='randint')
app.add_template_global(datetime, name='datetime')
app.add_template_global(timedelta, name='timedelta')
app.add_template_global(gethostname, name='gethostname')
app.add_template_global(min, name='min')
app.add_template_global(max, name='max')
# get git commit
output = subprocess.check_output(['git', "log", "-g", "-1", "--pretty=%H # %h # %d # %s"]).decode('UTF-8').split('#', 3)
app.jinja_env.globals['gitversion'] = { 'hash': output[1], 'longhash': output[0], 'branch': output[2], 'msg': output[3] }
@app.template_global() @app.template_global()
def ismod(*args): def ismod(*args):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment