aboutsummaryrefslogtreecommitdiff
path: root/gerboweb/job_processor.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2021-01-30 20:19:34 +0100
committerjaseg <git@jaseg.de>2021-01-30 20:19:34 +0100
commitc5f8416b63139ec5b69c318e1be70ae54755e1e6 (patch)
treed1d683996f0d3bf4cb65bce44e4e03254aadb3a0 /gerboweb/job_processor.py
parent2133867c8a86337c6668f9cfff06e4de9bd0bcce (diff)
parent3f3b8487d41b3e0beb081ff049e2c815d7e6b269 (diff)
downloadgerbolyze-c5f8416b63139ec5b69c318e1be70ae54755e1e6.tar.gz
gerbolyze-c5f8416b63139ec5b69c318e1be70ae54755e1e6.tar.bz2
gerbolyze-c5f8416b63139ec5b69c318e1be70ae54755e1e6.zip
Merge old gerbolyze history
Diffstat (limited to 'gerboweb/job_processor.py')
-rw-r--r--gerboweb/job_processor.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/gerboweb/job_processor.py b/gerboweb/job_processor.py
new file mode 100644
index 0000000..c138bf4
--- /dev/null
+++ b/gerboweb/job_processor.py
@@ -0,0 +1,40 @@
+
+import signal
+import subprocess
+import logging
+import itertools
+
+from job_queue import JobQueue
+
+
+if __name__ == '__main__':
+ import argparse
+ parser = argparse.ArgumentParser()
+ parser.add_argument('queue', help='job queue sqlite3 database file')
+ parser.add_argument('--loglevel', '-l', default='info')
+ args = parser.parse_args()
+
+ numeric_level = getattr(logging, args.loglevel.upper(), None)
+ if not isinstance(numeric_level, int):
+ raise ValueError('Invalid log level: %s' % loglevel)
+ logging.basicConfig(level=numeric_level)
+
+ job_queue = JobQueue(args.queue)
+
+ signal.signal(signal.SIGALRM, lambda *args: None) # Ignore incoming alarm signals while processing jobs
+ signal.setitimer(signal.ITIMER_REAL, 0.001, 1)
+ while signal.sigwait([signal.SIGALRM, signal.SIGINT]) == signal.SIGALRM:
+ logging.debug('Checking for jobs')
+ for job in job_queue.job_iter('render'):
+ logging.info(f'Processing {job.type} job {job.id} session {job["session_id"]} from {job.client} submitted {job.created}')
+ with job:
+ job.result = subprocess.call(['sudo', '/usr/local/sbin/gerbolyze_render.sh', job['session_id']])
+ logging.info(f'Finishied processing {job.type} job {job.id}')
+
+ for job in job_queue.job_iter('vector'):
+ logging.info(f'Processing {job.type} job {job.id} session {job["session_id"]} from {job.client} submitted {job.created}')
+ with job:
+ job.result = subprocess.call(['sudo', '/usr/local/sbin/gerbolyze_vector.sh', job['session_id'], job['side']])
+ logging.info(f'Finishied processing {job.type} job {job.id}')
+ logging.info('Caught SIGINT. Exiting.')
+