# Path: qpanel/backend.py
# class ConnectionErrorAMI(Exception):
# class Backend(object):
#     def __init__(self):
#     def is_freeswitch(self):
#     def is_asterisk(self):
#     def _connect(self):
#     def _connect_ami(self):
#     def _connect_esl(self):
#     def _get_data_queue_from_backend(self):
#     def get_data_queues(self, user=None):
#     def parse_data(self, data):
#     def filter_data_for_user(self, data, user):
#     def parse_fs(self, data):
#     def parse_asterisk(self, data):
#     def hide_queue(self, data):
#     def rename_queue(self, data):
#     def _call_spy(self, channel, to_exten, with_whisper=False):
#     def whisper(self, channel, to_exten):
#     def spy(self, channel, to_exten):
#     def barge(self, channel, to_exten):
#     def reset_stats(self, queue):
#     def hangup(self, channel):
#     def remove_from_queue(self, agent, queue):
# 
# Path: qpanel/config.py
# class NotConfigFileQPanel(BaseException):
# class QPanelConfig:
#     def __init__(self, file_path):
#     def __init__(self, path_config_file=None):
#     def __open_config_file(self, file_path):
#     def get_hide_config(self):
#     def get_show_config(self):
#     def __get_entry_ini_default(self, section, var, default):
#     def __get_bool_value_config(self, section, option, default):
#     def __get_entry_int_min_value(self, section, option, min=0):
#     def get(self, section, var):
#     def get_value_set_default(self, section, var, default):
#     def count_element_sections_config(self, section, cfg=None):
#     def has_users(self):
#     def has_user_queues(self):
#     def enable_queue_for_user(self, username, queuename):
#     def queue_enables_for_username(self, username):
#     def has_queuelog_config(self):
#     def has_section(self, section):
#     def is_freeswitch(self):
#     def queues_for_reset_stats(self):
#     def get_items(self, section):
#     def get_theme(self):
#     def realname_queue(self, queuename):


from qpanel import backend, config
from redis import Redis
from rq_scheduler import Scheduler
from rq import Connection, Worker
import datetime
import time
    """ Check if the params for configuration is present for reset_stats"""
    queues_for_reset = config.QPanelConfig().queues_for_reset_stats()
    entry = queues_for_reset.get(queuename)
    if entry and entry['when'] == when and entry['hour'] == hour:
        return True
    return False


def remove_jobs_not_config():
    """
        Remove jobs on queue but not present on config.
        Prevent when in job for reset a queue stats is scheduled but
        after your config is modified or deleted

        TODO: Maybe this could reload by notified in config.ini change
    """
    scheduler = Scheduler(connection=Redis())
    jobs = scheduler.get_jobs()
    for job in jobs:
        if 'reset_stats_queue' in job.func_name:
            # The args for the job of reset_stats_queue are:
            queuename = job.args[0]
            when = job.args[1]
            hour = job.args[2]

            if not exists_job_onconfig(queuename, when, hour):
                job.delete()


def enqueue_reset_stats():

# Path: qpanel/backend.py
# class ConnectionErrorAMI(Exception):
# class Backend(object):
#     def __init__(self):
#     def is_freeswitch(self):
#     def is_asterisk(self):
#     def _connect(self):
#     def _connect_ami(self):
#     def _connect_esl(self):
#     def _get_data_queue_from_backend(self):
#     def get_data_queues(self, user=None):
#     def parse_data(self, data):
#     def filter_data_for_user(self, data, user):
#     def parse_fs(self, data):
#     def parse_asterisk(self, data):
#     def hide_queue(self, data):
#     def rename_queue(self, data):
#     def _call_spy(self, channel, to_exten, with_whisper=False):
#     def whisper(self, channel, to_exten):
#     def spy(self, channel, to_exten):
#     def barge(self, channel, to_exten):
#     def reset_stats(self, queue):
#     def hangup(self, channel):
#     def remove_from_queue(self, agent, queue):
# 
# Path: qpanel/config.py
# class NotConfigFileQPanel(BaseException):
# class QPanelConfig:
#     def __init__(self, file_path):
#     def __init__(self, path_config_file=None):
#     def __open_config_file(self, file_path):
#     def get_hide_config(self):
#     def get_show_config(self):
#     def __get_entry_ini_default(self, section, var, default):
#     def __get_bool_value_config(self, section, option, default):
#     def __get_entry_int_min_value(self, section, option, min=0):
#     def get(self, section, var):
#     def get_value_set_default(self, section, var, default):
#     def count_element_sections_config(self, section, cfg=None):
#     def has_users(self):
#     def has_user_queues(self):
#     def enable_queue_for_user(self, username, queuename):
#     def queue_enables_for_username(self, username):
#     def has_queuelog_config(self):
#     def has_section(self, section):
#     def is_freeswitch(self):
#     def queues_for_reset_stats(self):
#     def get_items(self, section):
#     def get_theme(self):
#     def realname_queue(self, queuename):


# Path: qpanel/job.py
from qpanel import backend, config
from redis import Redis
from rq_scheduler import Scheduler
from rq import Connection, Worker
import datetime
import time

    """ Check if the params for configuration is present for reset_stats"""
    queues_for_reset = config.QPanelConfig().queues_for_reset_stats()
    entry = queues_for_reset.get(queuename)
    if entry and entry['when'] == when and entry['hour'] == hour:
        return True
    return False


def remove_jobs_not_config():
    """
        Remove jobs on queue but not present on config.
        Prevent when in job for reset a queue stats is scheduled but
        after your config is modified or deleted

        TODO: Maybe this could reload by notified in config.ini change
    """
    scheduler = Scheduler(connection=Redis())
    jobs = scheduler.get_jobs()
    for job in jobs:
        if 'reset_stats_queue' in job.func_name:
            # The args for the job of reset_stats_queue are:
            queuename = job.args[0]
            when = job.args[1]
            hour = job.args[2]

            if not exists_job_onconfig(queuename, when, hour):
                job.delete()


def enqueue_reset_stats():

    queues_for_reset = config.QPanelConfig().queues_for_reset_stats()