Commit 5bbbcd46 authored by Andreas Valder's avatar Andreas Valder

non functional prototype

parent 9d903bae
__pycache__
config.ini
#!/usr/bin/env python3
import config
import requests
import time
import threading
import sched
import random
import traceback
import configparser
if __name__ == '__main__':
print('foo')
config = configparser.ConfigParser()
config.read('config.ini')
scheduler = sched.scheduler()
def run_scheduler():
time.sleep(1) # weird things on startup
while True:
scheduler.run()
time.sleep(10)
def sched_func(delay, priority=0, firstdelay=None, args=[], kargs={}):
print(delay)
if firstdelay == None:
firstdelay = random.randint(1, 10)
def wrapper(func):
def sched_wrapper():
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()
@sched_func(5)
def ping_website():
r = requests.post(config['API']['BASE']+'/jobs/api/ping', params={'apikey': config['API']['KEY'], 'host':config['MAIN']['HOST']})
if not r.status_code == 200:
print("Error sending ping: ",r)
@sched_func(10)
def get_jobs():
r = requests.post(config['API']['BASE']+'/jobs/api/schedule', json={'apikey': config['API']['KEY'], 'host':config['MAIN']['HOST'], 'jobtypes': 'thumbnail'})
print(r.text)
while True:
time.sleep(10)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment