#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Stashr - Task Calls
"""

"""
MIT License

Copyright (c) 2020 Andrew Vanderbye

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

"""-------------------------------------------------------------------------------------------
-- IMPORTS
-------------------------------------------------------------------------------------------"""

""" --- HUEY IMPORT --- """
from stashr.stashr import huey
from huey import crontab

""" --- PYTHON IMPORTS --- """

""" --- STASHR DEPENDENCY IMPORTS --- """

""" --- STASHR CORE IMPORTS --- """
from stashr import log, utils

""" --- CREATE LOGGER --- """
logger = log.stashr_logger(__name__)

"""-------------------------------------------------------------------------------------------
-- TASKS
-------------------------------------------------------------------------------------------"""

""" --- SUBSCRIPTION TASKS --- """

""" --- SERIES TASKS --- """

""" --- RELEASE LIST TASKS --- """


# UPDATE RELEASE LIST
@huey.periodic_task(crontab(minute='*/120'))
def update_release_list_task():
    logger.debug('Update New Release Task')
    utils.update_release_list()


""" --- COMIC STATUS TASKS --- """

""" --- READING LIST TASKS --- """

""" --- COLLECTION TASKS --- """

""" --- SERVER TASKS --- """

""" --- PLUGIN TASKS --- """

"""" --- FILE TASKS --- """

""" --- DATABASE TASKS --- """

""" --- NEW TASKS --- """


@huey.task()
def scan_directories():
    utils.new_scan_directories()
    utils.new_create_scrape_entries()
    pass


@huey.task()
def add_scraped_directories():
    utils.new_add_scraped_matches()
    pass


""" --- HUEY CONFIGURE --- """


@huey.on_startup()
def huey_startup():
    log.disable_huey_logger()


"""-------------------------------------------------------------------------------------------
-- SIGNALS
-------------------------------------------------------------------------------------------"""


@huey.signal()
def task_signal(signal, task, exc=None):
    logger.info('[{0}] {1}'.format(signal, task))
    if signal == 'error':
        logger.error('[{0}] {1} - {2}'.format(signal, task, exc))