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.
Contains the EC2InstanceManager class, which helps manage the currently active instances.
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.
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. |
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.
Checks for job state changes in a non-blocking manner.
Calls the instance creation logic in a non-blocking manner.
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().
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.
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.
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.
Basic job caching module.
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.
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.
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. |
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. |
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. |
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. |
Loads all of the un-finished jobs into the job cache. This is performed when feederd starts.
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. |
Removes a job from the cache.
Parameters: | job (str or EncodingJob) – A job’s unique ID or a job object. |
---|
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.
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. |
---|