Example #1
0
def task_launch():
    camera_name = request.args.get('camera', None)
    task_name = request.args.get('task', None)
    if camera_name is None:
        return dict(msg="Camera name is missing")
    if task_name is None:
        return dict(msg="Task name is missing")
    job_name = f"{camera_name}_{task_name}"
    if job_name in jobs and jobs[job_name].is_alive():
        return dict(msg="Task already running")
    if task_name == 'tracking':
        jobs[job_name] = Process(target=cameras[camera_name].ObjectTracking)
        jobs[job_name].start()
        jobs[job_name].date = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
        return dict(running=jobs[job_name].is_alive(),
                    pid=jobs[job_name].pid,
                    name=jobs[job_name].name,
                    date=jobs[job_name].date)
    elif task_name == 'detection':
        jobs[job_name] = Process(
            target=cameras[camera_name].PeriodicCaptureContinous)
        jobs[job_name].start()
        jobs[job_name].date = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
        return dict(running=jobs[job_name].is_alive(),
                    pid=jobs[job_name].pid,
                    name=jobs[job_name].name,
                    date=jobs[job_name].date)
    else:
        return dict(msg="Don't know the task you want.\
                Try 'detection' or 'tracking'")