Ejemplo n.º 1
0
def channel_end(channel_id):
    from .models import Channel, ChannelProc
    logger.info("Closing channel with id {0}".format(channel_id))

    channel = Channel.objects.get(pk=channel_id)

    try:
        channel_proc = ChannelProc.objects.get(channel=channel)
        try:
            proc = psutil.Process(channel_proc.pid)
            proc.kill()
        except psutil.NoSuchProcess:
            logger.warning(
                "Channel proc with pid {0} does not exist"
                .format(channel_proc.pid)
            )
        channel_proc.delete()
    except ChannelProc.DoesNotExist:
        logger.warning(
            "There's no proc info for channel with id {0}"
            .format(channel_id)
        )

    logger.info("Closed channel with id {0}".format(channel_id))

    return
Ejemplo n.º 2
0
def podcast_check(podcast_id):
    from sources.models import PodcastSource
    logger.info("Checking PodcastSource with id {0}".format(podcast_id))
    try:
        podcast = PodcastSource.objects.get(pk=podcast_id)
        feed = feedparser.parse(podcast.url)
        last_entry = feed.entries[0]
        publish_date = parser.parse(last_entry.published)
        urls = []
        for enclosure in last_entry.enclosures:
            urls.append(enclosure.href)
        if ((podcast.last_date is None) or
                (publish_date > podcast.last_date) or
                (podcast.last_url not in urls)):
            download_podcast.delay(podcast_id, last_entry.published, urls[0])
    except PodcastSource.DoesNotExist:
        logger.error(
            "PodcastSource with id {0} does not exist".format(podcast_id)
        )
    except IndexError:
        logger.warning(
            "Feed for PodcastSource with id {0} has no content".format(
                podcast_id)
        )

    return
Ejemplo n.º 3
0
def mount_end(mount_id):
    from .models import Mount, MountProc
    logger.info("Ending mount with id {0}".format(mount_id))
    mount = Mount.objects.get(pk=mount_id)

    try:
        mount_proc = MountProc.objects.get(mount=mount)
        try:
            proc = psutil.Process(mount_proc.pid)
            proc.kill()
        except psutil.NoSuchProcess:
            logger.warning(
                "Mount proc with pid {0} does not exist"
                .format(mount_proc.pid)
            )
        mount_proc.delete()
    except MountProc.DoesNotExist:
        logger.warning(
            "There's no proc info for mount with id {0}"
            .format(mount_id)
        )

    logger.info("Ended mount with id {0}".format(mount_id))
    return
Ejemplo n.º 4
0
def manage_mount_proc(mount_id, is_post_save):
    from .models import Mount, MountProc
    logger.info("Managing status of mount with id {0}".format(mount_id))

    try:
        # Recover mount info
        mount = Mount.objects.get(pk=mount_id)
        mount_proc = None
        try:
            mount_proc = MountProc.objects.get(mount=mount)
        except MountProc.DoesNotExist:
            mount_proc = None

        # Manage stream status
        if (mount.channel.enabled):
            if (mount_proc is None):
                # Launch mount
                logger.info(
                        "Launching mount with id {0}".format(mount_id)
                    )
                mount_start.delay(mount.pk)
            else:
                # Check if mount is running
                try:
                    proc = psutil.Process(mount_proc.pid)
                    if proc.status() == psutil.STATUS_ZOMBIE:
                        logger.warning(
                            "Mount is not running (zombie process pid {0})"
                            .format(mount_proc.pid)
                            )
                        mount_proc.delete()
                        mount_start.delay(mount_id)
                    elif hash(proc) != mount_proc.hash:
                        logger.warning(
                            "Mount is not running (diff hash for pid {0})"
                            .format(mount_proc.pid)
                            )
                        mount_proc.delete()
                        mount_start.delay(mount_id)
                    else:
                        logger.info(
                            "Mount is running with pid {0}"
                            .format(mount_proc.pid)
                            )
                        if is_post_save:
                            mount_notify_save.delay(mount_id)
                except psutil.NoSuchProcess:
                    # If it's not running, restart
                    logger.warning(
                            "Mount proc with pid {0} does not exist"
                            .format(mount_proc.pid)
                        )
                    logger.info(
                        "Restarting mount with id {0}".format(mount_id)
                        )
                    mount_proc.delete()
                    mount_start.delay(mount_id)

        elif (not mount.channel.enabled) and (mount_proc is not None):
            # Close mount
            logger.info(
                    "Closing mount with id {0}".format(mount_id)
                )
            mount_end.delay(mount.pk)

        logger.info("Managed status of mount with id {0}".format(mount_id))
    except Mount.DoesNotExist:
        logger.error("Mount with id {0} does not exist".format(mount_id))

    return
Ejemplo n.º 5
0
def manage_channel_proc(channel_id, is_post_save):
    from .models import Channel, ChannelProc

    logger.info("Managing status of channel with id {0}".format(channel_id))

    try:
        # Recover channel info
        channel = Channel.objects.get(pk=channel_id)
        channel_proc = None
        try:
            channel_proc = ChannelProc.objects.get(channel=channel)
        except ChannelProc.DoesNotExist:
            channel_proc = None

        if (channel.enabled):
            if (channel_proc is None):
                # Launch channel
                logger.info(
                        "Launching channel with id {0}".format(channel_id)
                    )
                channel_start.delay(channel_id)
            else:
                # Check if channel is running
                try:
                    proc = psutil.Process(channel_proc.pid)
                    if proc.status() == psutil.STATUS_ZOMBIE:
                        logger.warning(
                            "Channel is not running (zombie process pid {0})"
                            .format(channel_proc.pid)
                            )
                        channel_proc.delete()
                        channel_start.delay(channel_id)
                    elif hash(proc) != channel_proc.hash:
                        logger.warning(
                            "Channel is not running (diff hash for pid {0})"
                            .format(channel_proc.pid)
                            )
                        channel_proc.delete()
                        channel_start.delay(channel_id)
                    else:
                        logger.info(
                            "Channel is running with pid {0}"
                            .format(channel_proc.pid)
                            )
                        if is_post_save:
                            channel_notify_save.delay(channel_id)
                except psutil.NoSuchProcess:
                    # If it's not running, restart
                    logger.warning(
                            "Channel proc with pid {0} does not exist"
                            .format(channel_proc.pid)
                        )
                    logger.info(
                        "Restarting channel with id {0}".format(channel_id)
                        )
                    channel_proc.delete()
                    channel_start.delay(channel_id)

        elif (not channel.enabled) and (channel_proc is not None):
            # Close channel
            logger.info(
                    "Closing channel with id {0}".format(channel_id)
                )
            channel_end.delay(channel.pk)

        for mount in channel.mount_set.all():
            manage_mount_proc.delay(mount.pk, is_post_save)

        logger.info(
            "Managed status of channel with id {0}".format(channel_id))

    except Channel.DoesNotExist:
        logger.error("Channel with id {0} does not exist".format(channel_id))

    return