# Path: ndscheduler/corescheduler/constants.py
# DEFAULT_JOBS_TABLENAME = 'scheduler_jobs'
# DEFAULT_EXECUTIONS_TABLENAME = 'scheduler_execution'
# DEFAULT_AUDIT_LOGS_TABLENAME = 'scheduler_jobauditlog'
# DEFAULT_THREAD_POOL_SIZE = 4
# DEFAULT_JOB_MAX_INSTANCES = 3
# DEFAULT_JOB_COALESCE = True
# DEFAULT_TIMEZONE = 'UTC'
# DEFAULT_JOB_MISFIRE_GRACE_SEC = 3600
# JOB_ARGS = 5
# EXECUTION_STATUS_SCHEDULED = 0
# EXECUTION_STATUS_RUNNING = 1
# EXECUTION_STATUS_STOPPING = 2
# EXECUTION_STATUS_STOPPED = 3
# EXECUTION_STATUS_FAILED = 4
# EXECUTION_STATUS_SUCCEEDED = 5
# EXECUTION_STATUS_TIMEOUT = 6
# EXECUTION_STATUS_SCHEDULED_ERROR = 7
# EXECUTION_STATUS_DICT = {
#     EXECUTION_STATUS_SCHEDULED: 'scheduled',
#     EXECUTION_STATUS_RUNNING: 'running',
#     EXECUTION_STATUS_STOPPING: 'stopping',
#     EXECUTION_STATUS_STOPPED: 'stopped',
#     EXECUTION_STATUS_FAILED: 'failed',
#     EXECUTION_STATUS_SUCCEEDED: 'succeeded',
#     EXECUTION_STATUS_TIMEOUT: 'timeout',
#     EXECUTION_STATUS_SCHEDULED_ERROR: 'scheduled error'
# }
# AUDIT_LOG_ADDED = 0
# AUDIT_LOG_MODIFIED = 1
# AUDIT_LOG_DELETED = 2
# AUDIT_LOG_PAUSED = 3
# AUDIT_LOG_RESUMED = 4
# AUDIT_LOG_CUSTOM_RUN = 5
# AUDIT_LOG_DICT = {
#     AUDIT_LOG_ADDED: 'added',
#     AUDIT_LOG_MODIFIED: 'modified',
#     AUDIT_LOG_DELETED: 'deleted',
#     AUDIT_LOG_PAUSED: 'paused',
#     AUDIT_LOG_RESUMED: 'resumed',
#     AUDIT_LOG_CUSTOM_RUN: 'custom_run'
# }
# 
# Path: ndscheduler/corescheduler/utils.py
# def import_from_path(path):
# def get_current_datetime():
# def get_job_name(job):
# def get_job_args(job):
# def get_job_kwargs(job):
# def get_cron_strings(job):
# def generate_uuid():
# def get_stacktrace():
# def get_hostname():
# def get_pid():
# def get_datastore_instance(datastore_class_path, db_config=None, db_tablenames=None):
# 
# Path: ndscheduler/corescheduler/datastore/tables.py
# def get_execution_table(metadata, tablename):
# def get_auditlogs_table(metadata, tablename):


import dateutil.tz
import dateutil.parser
from apscheduler.jobstores import sqlalchemy as sched_sqlalchemy
from sqlalchemy import desc, select, MetaData
from ndscheduler.corescheduler import constants
from ndscheduler.corescheduler import utils
from ndscheduler.corescheduler.datastore import tables
        :param str execution_id: Execution id.
        :param kwargs: Keyword arguments.
        """
        execution_update = self.executions_table.update().where(
            self.executions_table.c.eid == execution_id).values(**kwargs)
        self.engine.execute(execution_update)

    def _build_execution(self, row):
        """Return job execution info from a row of scheduler_execution table.
        :param obj row: A row instance of scheduler_execution table.
        :return: A dictionary of job execution info.
        :rtype: dict
        """
        return_json = {
            'execution_id': row.eid,
            'state': constants.EXECUTION_STATUS_DICT[row.state],
            'hostname': row.hostname,
            'pid': row.pid,
            'task_id': row.task_id,
            'description': row.description,
            'result': row.result,
            'scheduled_time': self.get_time_isoformat_from_db(row.scheduled_time),
            'updated_time': self.get_time_isoformat_from_db(row.updated_time)}
        job = self.lookup_job(row.job_id)
        if job:
            return_json['job'] = {
                'job_id': job.id,
                'name': job.name,
                'task_name': utils.get_job_name(job),
                'pub_args': utils.get_job_args(job)}

# Path: ndscheduler/corescheduler/constants.py
# DEFAULT_JOBS_TABLENAME = 'scheduler_jobs'
# DEFAULT_EXECUTIONS_TABLENAME = 'scheduler_execution'
# DEFAULT_AUDIT_LOGS_TABLENAME = 'scheduler_jobauditlog'
# DEFAULT_THREAD_POOL_SIZE = 4
# DEFAULT_JOB_MAX_INSTANCES = 3
# DEFAULT_JOB_COALESCE = True
# DEFAULT_TIMEZONE = 'UTC'
# DEFAULT_JOB_MISFIRE_GRACE_SEC = 3600
# JOB_ARGS = 5
# EXECUTION_STATUS_SCHEDULED = 0
# EXECUTION_STATUS_RUNNING = 1
# EXECUTION_STATUS_STOPPING = 2
# EXECUTION_STATUS_STOPPED = 3
# EXECUTION_STATUS_FAILED = 4
# EXECUTION_STATUS_SUCCEEDED = 5
# EXECUTION_STATUS_TIMEOUT = 6
# EXECUTION_STATUS_SCHEDULED_ERROR = 7
# EXECUTION_STATUS_DICT = {
#     EXECUTION_STATUS_SCHEDULED: 'scheduled',
#     EXECUTION_STATUS_RUNNING: 'running',
#     EXECUTION_STATUS_STOPPING: 'stopping',
#     EXECUTION_STATUS_STOPPED: 'stopped',
#     EXECUTION_STATUS_FAILED: 'failed',
#     EXECUTION_STATUS_SUCCEEDED: 'succeeded',
#     EXECUTION_STATUS_TIMEOUT: 'timeout',
#     EXECUTION_STATUS_SCHEDULED_ERROR: 'scheduled error'
# }
# AUDIT_LOG_ADDED = 0
# AUDIT_LOG_MODIFIED = 1
# AUDIT_LOG_DELETED = 2
# AUDIT_LOG_PAUSED = 3
# AUDIT_LOG_RESUMED = 4
# AUDIT_LOG_CUSTOM_RUN = 5
# AUDIT_LOG_DICT = {
#     AUDIT_LOG_ADDED: 'added',
#     AUDIT_LOG_MODIFIED: 'modified',
#     AUDIT_LOG_DELETED: 'deleted',
#     AUDIT_LOG_PAUSED: 'paused',
#     AUDIT_LOG_RESUMED: 'resumed',
#     AUDIT_LOG_CUSTOM_RUN: 'custom_run'
# }
# 
# Path: ndscheduler/corescheduler/utils.py
# def import_from_path(path):
# def get_current_datetime():
# def get_job_name(job):
# def get_job_args(job):
# def get_job_kwargs(job):
# def get_cron_strings(job):
# def generate_uuid():
# def get_stacktrace():
# def get_hostname():
# def get_pid():
# def get_datastore_instance(datastore_class_path, db_config=None, db_tablenames=None):
# 
# Path: ndscheduler/corescheduler/datastore/tables.py
# def get_execution_table(metadata, tablename):
# def get_auditlogs_table(metadata, tablename):


# Path: ndscheduler/corescheduler/datastore/base.py
import dateutil.tz
import dateutil.parser
from apscheduler.jobstores import sqlalchemy as sched_sqlalchemy
from sqlalchemy import desc, select, MetaData
from ndscheduler.corescheduler import constants
from ndscheduler.corescheduler import utils
from ndscheduler.corescheduler.datastore import tables

        :param str execution_id: Execution id.
        :param kwargs: Keyword arguments.
        """
        execution_update = self.executions_table.update().where(
            self.executions_table.c.eid == execution_id).values(**kwargs)
        self.engine.execute(execution_update)

    def _build_execution(self, row):
        """Return job execution info from a row of scheduler_execution table.
        :param obj row: A row instance of scheduler_execution table.
        :return: A dictionary of job execution info.
        :rtype: dict
        """
        return_json = {
            'execution_id': row.eid,
            'state': constants.EXECUTION_STATUS_DICT[row.state],
            'hostname': row.hostname,
            'pid': row.pid,
            'task_id': row.task_id,
            'description': row.description,
            'result': row.result,
            'scheduled_time': self.get_time_isoformat_from_db(row.scheduled_time),
            'updated_time': self.get_time_isoformat_from_db(row.updated_time)}
        job = self.lookup_job(row.job_id)
        if job:
            return_json['job'] = {
                'job_id': job.id,
                'name': job.name,
                'task_name': utils.get_job_name(job),
                'pub_args': utils.get_job_args(job)}

            return_json['job'].update(utils.get_cron_strings(job))