import logging

from model.customexception import RestartComponentException

from msgbus import TK_CMP_TERM_NOW
from sysactions import send_message

logger = logging.getLogger("PosActions")


def restart_pos(
    pos_id,     # type: str
):
    # type: (...) -> None

    logger.info("Restarting POS {}".format(pos_id))
    component = "POS%d" % int(pos_id)
    response = send_message(
        dest_name=component,
        token=TK_CMP_TERM_NOW,
        timeout=600000000
    )
    if response.token != TK_CMP_TERM_NOW:
        raise RestartComponentException(
            component=component,
            token=response.token,
            data=response.data,
        )

    logger.info("POS {} successfully restarted".format(pos_id))
