media_nommer.feederd

This module contains the logic for the Twisted daemon that oversees the encoding process, feederd. Only things that are specific to this daemon should reside within this module. Anything that could conceivably also be useful to media_nommer.ec2nommerd should probably be in media_nommer.core.

ec2_instance_manager

Contains the EC2InstanceManager class, which helps manage the currently active instances.

class media_nommer.feederd.ec2_instance_manager.EC2InstanceManager[source]

This class managers and creates EC2 instances from the configured encoder AMI. Additional instances are spawned based on the size of the job queue in relation to the amount of manpower available at any point in time.

classmethod get_instances()[source]

Returns a list of boto Instance objects matching the media-nommer AMI, as per media_nommer.conf.settings.EC2_AMI_ID. Also filters only running instances.

Return type:list
Returns:A list of boto.ec2.instance.Instance objects representing currently active media-nommer ec2nommerd instances.
classmethod spawn_if_needed()[source]

Spawns additional EC2 instances if needed.

Return type:boto.ec2.instance.Reservation or None
Returns:If instances are spawned, return a boto Reservation object. If no instances are spawned, None is returned.
classmethod spawn_instances(num_instances)[source]

Spawns the number of instances specified.

Parameters:num_instances (int) – The number of instances to spawn.
Return type:boto.ec2.instance.Reservation
Returns:A boto Reservation for the started instance(s).

interval_tasks

This module contains tasks that are executed at intervals, and is imported at the time the server is started. Much of feederd‘s ‘intelligence’ can be found here.

All functions prefixed with task_ are task functions that are registered with the Twisted reactor. All functions prefixed with threaded_ are the interesting bits that actually do things.

media_nommer.feederd.interval_tasks.register_tasks()[source]

Registers all tasks. Called by the feederd Twisted plugin.

media_nommer.feederd.interval_tasks.task_check_for_job_state_changes()[source]

Checks for job state changes in a non-blocking manner.

Calls threaded_check_for_job_state_changes().

media_nommer.feederd.interval_tasks.task_manage_ec2_instances()[source]

Calls the instance creation logic in a non-blocking manner.

Calls threaded_manage_ec2_instances().

media_nommer.feederd.interval_tasks.task_prune_jobs()[source]

Prune expired or abandoned jobs from the domain specified in the SIMPLEDB_JOB_STATE_DOMAIN setting. Also prunes feederd‘s job cache.

Calls threaded_prune_jobs().

media_nommer.feederd.interval_tasks.threaded_check_for_job_state_changes()[source]

Checks the SQS queue specified in the SQS_JOB_STATE_CHANGE_QUEUE_NAME setting for announcements of state changes from the EC2 instances running ec2nommerd. This lets feederd know it needs to get updated job details from the SimpleDB domain defined in the SIMPLEDB_JOB_STATE_DOMAIN setting.

media_nommer.feederd.interval_tasks.threaded_manage_ec2_instances()[source]

Looks at the current number of jobs needing encoding and compares them to the pool of currently running EC2 instances. Spawns more instances as needed.

See source of media_nommer.feederd.ec2_instance_manager.EC2InstanceManager.spawn_if_needed() for the logic behind this.

media_nommer.feederd.interval_tasks.threaded_prune_jobs()[source]

Sometimes failure happens, but a Nommer doesn’t handle said failure gracefully. Instead of state changing to ERROR, it gets stuck in some un-finished state in the SimpleDB domain defined in SIMPLEDB_JOB_STATE_DOMAIN setting.

This process finds jobs that haven’t been updated in a very long time (a day or so) that are probably dead. It marks them with an ABANDONED state, letting us know something went really wrong.

job_cache

Basic job caching module.

class media_nommer.feederd.job_cache.JobCache[source]

Caches currently active media_nommer.core.job_state_backend.EncodingJob objects. This is presently only un-finished jobs, as defined by media_nommer.core.job_state_backend.JobStateBackend.FINISHED_STATES.

CACHE = {}
classmethod abandon_stale_jobs()[source]

On rare occasions, nommers crash so hard that no ERROR state change is made, and the job just gets stuck in a permanent unfinished state (DOWNLOADING, ENCODING, UPLOADING, etc). Rather than hang on to these indefinitely, abandon them by setting their state to ABANDONED.

The threshold for which jobs are considered abandoned is configurable via the FEEDERD_ABANDON_INACTIVE_JOBS_THRESH setting.

classmethod get_cached_jobs()[source]

Returns a dict of all cached jobs. The keys are unique IDs, the values are the job objects.

Return type:dict
Returns:A dictionary with the keys being unique IDs of cached jobs, and the values being EncodingJob instances.
classmethod get_job(job)[source]

Given a job’s unique id, return the job object from the cache.

Parameters:job (EncodingJob) – A job’s unique ID or a job object.
Return type:EncodingJob
Returns:The cached encoding job.
classmethod get_jobs_with_state(state)[source]

Given a valid job state (refer to media_nommer.core.job_state_backend.JobStateBackend.JOB_STATES), return all jobs that currently have this state.

Parameters:state (str) – The job state to query by.
Return type:list of EncodingJob
Returns:A list of jobs matching the given state.
classmethod is_job_cached(job)[source]

Given a job object or a unique id, return True if said job is cached, and False if not.

Parameters:job (str or EncodingJob) – A job’s unique ID or a job object.
Return type:bool
Returns:True if the given job exists in the cache, False if otherwise.
classmethod load_recent_jobs_at_startup()[source]

Loads all of the un-finished jobs into the job cache. This is performed when feederd starts.

classmethod refresh_jobs_with_state_changes()[source]

Looks at the state SQS queue specified by the SQS_JOB_STATE_CHANGE_QUEUE_NAME setting and refreshes any jobs that have changed. This simply reloads the job’s details from SimpleDB.

Return type:list of EncodingJob
Returns:A list of changed EncodingJob objects.
classmethod remove_job(job)[source]

Removes a job from the cache.

Parameters:job (str or EncodingJob) – A job’s unique ID or a job object.
classmethod uncache_finished_jobs()[source]

Clears jobs from the cache after they have been finished.

TODO: We’ll eventually want to clear jobs from the cache that haven’t been accessed by the web API recently.

classmethod update_job(job)[source]

Updates a job in the cache. Creates the key if it doesn’t already exist.

Parameters:job (EncodingJob) – The job to update (or create) a cache entry for.

Table Of Contents

Previous topic

media_nommer.ec2nommerd

This Page