change how we calculate active jobs, probably will remove it from pa_job_engine, safer with threads I think. But, mostyle, added in client / server socket comms between web FE and job manager, with better job creation message (including link to job detail) and when you view job detail it auto-refreshes every few seconds until job complete)
This commit is contained in:
@@ -16,7 +16,7 @@ from sqlalchemy import Column, Integer, String, Sequence, Float, ForeignKey, Dat
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from shared import DB_URL
|
||||
from shared import DB_URL, PA_JOB_MANAGER_HOST, PA_JOB_MANAGER_PORT
|
||||
from datetime import datetime, timedelta
|
||||
import pytz
|
||||
import time
|
||||
@@ -29,6 +29,8 @@ import exifread
|
||||
import base64
|
||||
import numpy
|
||||
import cv2
|
||||
import socket
|
||||
import threading
|
||||
|
||||
# an Manager, which the Session will use for connection resources
|
||||
some_engine = create_engine(DB_URL)
|
||||
@@ -169,6 +171,7 @@ class FileData():
|
||||
AddLogForJob(job, "Found new file: {}".format(fname) )
|
||||
else:
|
||||
AddLogForJob(job, "DEBUG: {} - {} is OLDER than {}".format( file, stat.st_ctime, last_import_date ), file )
|
||||
time.sleep(0.4)
|
||||
settings.last_import_date = time.time()
|
||||
session.commit()
|
||||
return self
|
||||
@@ -297,14 +300,17 @@ def RunJob(job):
|
||||
return
|
||||
|
||||
def HandleJobs():
|
||||
print("PA job manager is scanning for jobs")
|
||||
global pa_eng
|
||||
|
||||
print("PA job manager is scanning for new jobs to process")
|
||||
pa_eng.state = 'Scanning Jobs'
|
||||
jobs=GetJobs()
|
||||
pa_eng.num_active_jobs=0
|
||||
pa_eng.num_completed_jobs=0
|
||||
for job in jobs:
|
||||
if job.pa_job_state != 'Completed':
|
||||
RunJob(job)
|
||||
threading.Thread(target=RunJob, args=(job,)).start()
|
||||
print ("HandleJobs setting num_active jobs to +1")
|
||||
pa_eng.num_active_jobs = pa_eng.num_active_jobs + 1
|
||||
else:
|
||||
pa_eng.num_completed_jobs = pa_eng.num_completed_jobs +1
|
||||
@@ -346,4 +352,10 @@ if __name__ == "__main__":
|
||||
print( "Failed to initialise PA Job Manager: {}".format(e) )
|
||||
session.rollback()
|
||||
HandleJobs()
|
||||
print("Exiting for now: {}".format( pa_eng ))
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.bind((PA_JOB_MANAGER_HOST, PA_JOB_MANAGER_PORT))
|
||||
s.listen()
|
||||
while True:
|
||||
conn, addr = s.accept()
|
||||
print("Connection from: {} so HandleJobs".format(addr))
|
||||
HandleJobs()
|
||||
|
||||
Reference in New Issue
Block a user