# Path: media_nommer/conf/settings.py
# AWS_ACCESS_KEY_ID = None
# AWS_SECRET_ACCESS_KEY = None
# CONFIG_S3_BUCKET = 'nommer_config'
# SQS_NEW_JOB_QUEUE_NAME = 'media_nommer'
# SQS_JOB_STATE_CHANGE_QUEUE_NAME = 'media_nommer_jstate'
# SIMPLEDB_JOB_STATE_DOMAIN = 'media_nommer'
# SIMPLEDB_EC2_NOMMER_STATE_DOMAIN = 'media_nommer_ec2nommer_state'
# EC2_KEY_NAME = None
# EC2_SECURITY_GROUPS = ['media_nommer']
# EC2_AMI_ID = 'ami-eb558182'
# EC2_INSTANCE_TYPE = 'm1.large'
# MAX_ENCODING_JOBS_PER_EC2_INSTANCE = 2
# MAX_NUM_EC2_INSTANCES = 3
# JOB_OVERFLOW_THRESH = 2
# FEEDERD_JOB_STATE_CHANGE_CHECK_INTERVAL = 60
# FEEDERD_PRUNE_JOBS_INTERVAL = 60 * 5
# FEEDERD_ALLOW_EC2_LAUNCHES = True
# FEEDERD_ABANDON_INACTIVE_JOBS_THRESH = 3600 * 9
# FEEDERD_AUTO_SCALE_INTERVAL = 60
# NOMMERD_TERMINATE_WHEN_IDLE = True
# NOMMERD_MAX_INACTIVITY = 60 * 10
# NOMMERD_HEARTBEAT_INTERVAL = 60
# NOMMERD_NEW_JOB_CHECK_INTERVAL = 60
# NOMMERD_QTFASTSTART_BIN_PATH = '/home/nom/.virtualenvs/media_nommer/bin/qtfaststart'
# STORAGE_BACKENDS = {
#     's3': 'media_nommer.core.storage_backends.s3.S3Backend',
#     'http': 'media_nommer.core.storage_backends.http.HTTPBackend',
#     'https': 'media_nommer.core.storage_backends.http.HTTPBackend',
#     'file': 'media_nommer.core.storage_backends.file.FileBackend',
# }
# 
# Path: media_nommer/utils/logger.py
# def debug(message):
# def info(message):
# def warning(message):
# def error(message_or_obj=None):
# 
# Path: media_nommer/utils/compat.py
# def total_seconds(td):
#     """
#     Given a timedelta object, compute the total number of seconds elapsed
#     for the entire delta. This is only available in the standard library for
#     Python 2.7 and up.
#     
#     Source: http://docs.python.org/library/datetime.html#datetime.timedelta.total_seconds
#     
#     :param datetime.timedelta td: A timedelta instance.
#     :rtype: float
#     :returns: The seconds elapsed during the timedelta.
#     """
#     return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6) / 10 ** 6.0


import urllib2
import datetime
import boto
from twisted.internet import reactor
from media_nommer.conf import settings
from media_nommer.utils import logger
from media_nommer.utils.compat import total_seconds
            item.save()

    @classmethod
    def contemplate_termination(cls, thread_count_mod=0):
        """
        Looks at how long it's been since this worker has done something, and
        decides whether to self-terminate.
        
        :param int thread_count_mod: Add this to the amount returned by the call
            to :py:meth:`get_num_active_threads`. This is useful when calling
            this method from a non-encoder thread.
        :rtype: bool
        :returns: ``True`` if this instance terminated itself, ``False``
            if not.
        """
        if not cls.is_ec2_instance():
            # Developing locally, don't go here.
            return False

        # This is -1 since this is also a thread doing the contemplation.
        # This would always be 1, even if we had no jobs encoding, if we
        # didn't take into account this thread.
        num_active_threads = cls.get_num_active_threads() + thread_count_mod

        if num_active_threads > 0:
            # Encoding right now, don't terminate.
            return False

        tdelt = datetime.datetime.now() - cls.last_dtime_i_did_something
        # Total seconds of inactivity.

# Path: media_nommer/conf/settings.py
# AWS_ACCESS_KEY_ID = None
# AWS_SECRET_ACCESS_KEY = None
# CONFIG_S3_BUCKET = 'nommer_config'
# SQS_NEW_JOB_QUEUE_NAME = 'media_nommer'
# SQS_JOB_STATE_CHANGE_QUEUE_NAME = 'media_nommer_jstate'
# SIMPLEDB_JOB_STATE_DOMAIN = 'media_nommer'
# SIMPLEDB_EC2_NOMMER_STATE_DOMAIN = 'media_nommer_ec2nommer_state'
# EC2_KEY_NAME = None
# EC2_SECURITY_GROUPS = ['media_nommer']
# EC2_AMI_ID = 'ami-eb558182'
# EC2_INSTANCE_TYPE = 'm1.large'
# MAX_ENCODING_JOBS_PER_EC2_INSTANCE = 2
# MAX_NUM_EC2_INSTANCES = 3
# JOB_OVERFLOW_THRESH = 2
# FEEDERD_JOB_STATE_CHANGE_CHECK_INTERVAL = 60
# FEEDERD_PRUNE_JOBS_INTERVAL = 60 * 5
# FEEDERD_ALLOW_EC2_LAUNCHES = True
# FEEDERD_ABANDON_INACTIVE_JOBS_THRESH = 3600 * 9
# FEEDERD_AUTO_SCALE_INTERVAL = 60
# NOMMERD_TERMINATE_WHEN_IDLE = True
# NOMMERD_MAX_INACTIVITY = 60 * 10
# NOMMERD_HEARTBEAT_INTERVAL = 60
# NOMMERD_NEW_JOB_CHECK_INTERVAL = 60
# NOMMERD_QTFASTSTART_BIN_PATH = '/home/nom/.virtualenvs/media_nommer/bin/qtfaststart'
# STORAGE_BACKENDS = {
#     's3': 'media_nommer.core.storage_backends.s3.S3Backend',
#     'http': 'media_nommer.core.storage_backends.http.HTTPBackend',
#     'https': 'media_nommer.core.storage_backends.http.HTTPBackend',
#     'file': 'media_nommer.core.storage_backends.file.FileBackend',
# }
# 
# Path: media_nommer/utils/logger.py
# def debug(message):
# def info(message):
# def warning(message):
# def error(message_or_obj=None):
# 
# Path: media_nommer/utils/compat.py
# def total_seconds(td):
#     """
#     Given a timedelta object, compute the total number of seconds elapsed
#     for the entire delta. This is only available in the standard library for
#     Python 2.7 and up.
#     
#     Source: http://docs.python.org/library/datetime.html#datetime.timedelta.total_seconds
#     
#     :param datetime.timedelta td: A timedelta instance.
#     :rtype: float
#     :returns: The seconds elapsed during the timedelta.
#     """
#     return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6) / 10 ** 6.0


# Path: media_nommer/ec2nommerd/node_state.py
import urllib2
import datetime
import boto
from twisted.internet import reactor
from media_nommer.conf import settings
from media_nommer.utils import logger
from media_nommer.utils.compat import total_seconds

            item.save()

    @classmethod
    def contemplate_termination(cls, thread_count_mod=0):
        """
        Looks at how long it's been since this worker has done something, and
        decides whether to self-terminate.
        
        :param int thread_count_mod: Add this to the amount returned by the call
            to :py:meth:`get_num_active_threads`. This is useful when calling
            this method from a non-encoder thread.
        :rtype: bool
        :returns: ``True`` if this instance terminated itself, ``False``
            if not.
        """
        if not cls.is_ec2_instance():
            # Developing locally, don't go here.
            return False

        # This is -1 since this is also a thread doing the contemplation.
        # This would always be 1, even if we had no jobs encoding, if we
        # didn't take into account this thread.
        num_active_threads = cls.get_num_active_threads() + thread_count_mod

        if num_active_threads > 0:
            # Encoding right now, don't terminate.
            return False

        tdelt = datetime.datetime.now() - cls.last_dtime_i_did_something
        # Total seconds of inactivity.

        inactive_secs = total_seconds(tdelt)