# Path: ui/cron_jobs.py
# def archive_job_manager(logger):
#     jobs = FileArchive.objects.filter(status=0)
#     # mark as in queue
#     for job in jobs:
#         try:
#             job.status = -1
#             job.save()
#         except Exception as e:
#             logger.error(e)
#     # actually handle with these samples
#     for job in jobs:
#         try:
#             logger.info("Archiving %d" % (job.id))
#             save_job(job.id, logger)
#         except Exception as e:
#             logger.error(e)
# 
# def audit_job_manager(logger):
#     counts, msg = audit_job_atom()
#     if counts == -1:
#         logger.error(msg)
#     else:
#         logger.info("Audit finished, %d jobs need audition" % counts)
# 
# def audit_archiving_file_manager(logger):
#     try:
#         jobs = FileArchive.objects.all()
#         for job in jobs:
#             if job.protocol_ver != job.protocol.ver:
#                 job.audit = 1
#                 job.save()
#     except Exception as e:
#         logger.error(e)


import time
import threading
import logging
import os
import sys
from django.core.wsgi import get_wsgi_application
from ui.cron_jobs import archive_job_manager, audit_job_manager, audit_archiving_file_manager
#!/usr/bin/env python
# coding=utf-8
# @Author: Li Yao
# @Date: 01/28/20

sys.path.append(os.path.split(os.path.split(os.path.realpath(__file__))[0])[0])
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "BioQueue.settings")

application = get_wsgi_application()

DEFAULT_PREFIX = str(os.getpid())
logging.basicConfig(format='%(name)s - %(asctime)s - %(levelname)s: %(message)s',
                    datefmt='%d-%b-%y %H:%M:%S',
                    level=logging.INFO,
                    handlers=[
                        logging.FileHandler(os.path.join(os.getcwd(), 'cron_%s.log' % DEFAULT_PREFIX)),
                        logging.StreamHandler()
                    ])
logger = logging.getLogger("BioQueue - Cron")


def aj_cron(logger):
    while True:
        logger.info("Cron - File archive")

# Path: ui/cron_jobs.py
# def archive_job_manager(logger):
#     jobs = FileArchive.objects.filter(status=0)
#     # mark as in queue
#     for job in jobs:
#         try:
#             job.status = -1
#             job.save()
#         except Exception as e:
#             logger.error(e)
#     # actually handle with these samples
#     for job in jobs:
#         try:
#             logger.info("Archiving %d" % (job.id))
#             save_job(job.id, logger)
#         except Exception as e:
#             logger.error(e)
# 
# def audit_job_manager(logger):
#     counts, msg = audit_job_atom()
#     if counts == -1:
#         logger.error(msg)
#     else:
#         logger.info("Audit finished, %d jobs need audition" % counts)
# 
# def audit_archiving_file_manager(logger):
#     try:
#         jobs = FileArchive.objects.all()
#         for job in jobs:
#             if job.protocol_ver != job.protocol.ver:
#                 job.audit = 1
#                 job.save()
#     except Exception as e:
#         logger.error(e)


# Path: ui/cron_runner.py
import time
import threading
import logging
import os
import sys
from django.core.wsgi import get_wsgi_application
from ui.cron_jobs import archive_job_manager, audit_job_manager, audit_archiving_file_manager

#!/usr/bin/env python
# coding=utf-8
# @Author: Li Yao
# @Date: 01/28/20

sys.path.append(os.path.split(os.path.split(os.path.realpath(__file__))[0])[0])
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "BioQueue.settings")

application = get_wsgi_application()

DEFAULT_PREFIX = str(os.getpid())
logging.basicConfig(format='%(name)s - %(asctime)s - %(levelname)s: %(message)s',
                    datefmt='%d-%b-%y %H:%M:%S',
                    level=logging.INFO,
                    handlers=[
                        logging.FileHandler(os.path.join(os.getcwd(), 'cron_%s.log' % DEFAULT_PREFIX)),
                        logging.StreamHandler()
                    ])
logger = logging.getLogger("BioQueue - Cron")


def aj_cron(logger):
    while True:
        logger.info("Cron - File archive")

        archive_job_manager(logger)