Commit 44ec93b9 authored by Andreas Valder's avatar Andreas Valder

made worker faster

parent 8609f969
......@@ -17,7 +17,7 @@ def run_scheduler():
time.sleep(1) # weird things on startup
while True:
scheduler.run()
time.sleep(10)
time.sleep(1)
def sched_func(delay, priority=0, firstdelay=None, args=[], kargs={}):
if firstdelay == None:
......@@ -43,7 +43,6 @@ def ping_website_for_host():
if not api.worker_ping():
print("Error sending host ping")
@sched_func(10)
def get_job():
if psutil.cpu_percent(interval=3) > 85:
return
......@@ -54,4 +53,4 @@ def get_job():
subprocess.Popen(['./worker.py', str(j['id']), str(j['type']), str(j['priority']) , str(j['data']) ] )
while True:
time.sleep(10)
get_job()
......@@ -2,10 +2,11 @@
import time
import traceback
import configparser
import os
import json
import shlex
import sys
import subprocess
import os
from workerapi import WorkerApi
config = configparser.ConfigParser()
......@@ -23,5 +24,10 @@ if (jobtype == 'thumbnail'):
inputfile = '/mnt/sshfs/video-main/'+data['path']
outputfile = '/tmp/l_'+str(data['lectureid'])+'.png'
api.job_ping(id=id)
os.system("ffmpeg -loglevel error -i '" + shlex.quote(inputfile) + "' -ss '10:00' -vf 'scale=640:360' -frames:v 1 '" + shlex.quote(outputfile) + "'")
api.job_ping(id=id,state='finished')
duration = float(subprocess.run(["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", inputfile], stdout=subprocess.PIPE).stdout)
api.job_ping(id=id)
if subprocess.run(["ffmpeg", "-loglevel", "error", "-ss", str(duration*0.4), "-i", inputfile, "-vf", "scale=640:360", "-frames:v", "1", outputfile]).returncode == 0:
api.job_ping(id=id,state='finished')
else:
api.job_ping(id=id,state='failed')
print('failed')
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