def _init(self):
     try:
         os.unlink(settings.metadata)
     except OSError:
         pass
     initialize_db(db_name=settings.metadata)
     self.jobs_config = sync_jobs(settings)
    def test_initialize_db(self):
        try:
            os.unlink(settings.metadata)
        except OSError:
            pass
        initialize_db(db_name=settings.metadata)
        job_id, schedule_time, execution_time, status, runs, uid = u'dummy_job', u'2015-09-12T00:00:00', u'', 0, 0, u'0'
        expected_result = [job_id, schedule_time, execution_time, status, runs, uid]
        insert_dummy_job(job_id, schedule_time, execution_time, status, runs, uid, db_name=settings.metadata)
        result = read_all_jobs(db_name=settings.metadata)
        self.assertEqual(len(result), 1)
        os.unlink(settings.metadata)

        self.assertEqual(list(result[0]), expected_result)
    def test_sync_jobs(self):
        initialize_db(db_name=settings.metadata)
        result = sync_jobs(settings)
        db_jobs = read_all_jobs(db_name=settings.metadata)

        self.assertEqual(len(db_jobs), len(result) * (settings.metadata_history_days + settings.metadata_future_days))
Ejemplo n.º 4
0
def drone_runner():
    while True:
        jobs_config = sync_jobs(settings)
        for job_config in jobs_config:
            process(job_config, settings)
        sleep(settings.schedule_interval_seconds)


def web_runner(app=api_app):
    app.run(debug=settings.debug,
            use_reloader=settings.use_reloader,
            host=settings.host_ip,
            port=settings.port,
            threaded=True,
            processes=1)


if __name__ == "__main__":
    try:
        initialize_db(db_name=settings.metadata)

        with futures.ProcessPoolExecutor(max_workers=2) as executors:
            executors.submit(web_runner)
            executors.submit(drone_runner)

    except KeyboardInterrupt:
        exit()
    except:
        raise