Sanitycheck Panda config on load and clean up the example config file

* Clearer example config file with more documentation
* Made defaults more sensible.
* Checks that all required config options have been set
* Warns if no encoding profiles exist.
This commit is contained in:
Martyn Loughran 2008-10-10 16:37:56 +01:00
Родитель 25d813e450
Коммит 9a33fc5369
7 изменённых файлов: 99 добавлений и 39 удалений

Просмотреть файл

@ -1,4 +1,10 @@
class Profile < SimpleDB::Base
set_domain Panda::Config[:sdb_profiles_domain]
properties :title, :player, :container, :width, :height, :video_codec, :video_bitrate, :fps, :audio_codec, :audio_bitrate, :audio_sample_rate, :position, :updated_at, :created_at
def self.warn_if_no_encodings
if Profile.query.empty?
Merb.logger.info "PANDA CONFIG ERROR: There are no encoding profiles. You probably forgot to define them. Please see the getting started guide."
end
end
end

Просмотреть файл

@ -29,6 +29,8 @@ dependencies 'local_store'
require 'aws/s3'
require 'inline'
Panda::Config.check
Merb::BootLoader.after_app_loads do
# Panda specific
@ -56,6 +58,7 @@ Merb::BootLoader.after_app_loads do
end
LocalStore.ensure_directories_exist
Profile.warn_if_no_encodings
end
EMAIL_SENDER = "Panda <info@pandastream.com>"

Просмотреть файл

@ -1,18 +1,26 @@
require 'panda'
require 'panda'
Panda::Config.use do |p|
p[:account_name] = "New Bamboo"
p[:api_key] = "f9e3425-16fd-012b-731d-001ec2b5c0e1"
p[:upload_redirect_url] = "http://localhost:4000/videos/$id/done"
p[:state_update_url] = "http://localhost:4000/videos/$id/status_update"
# p[:account_name] = "OPTIONAL_STRING_TO_IDENTIFY_PANDA_INSTANCE"
# =====================================================
# Local storage. Public is accessible from the internet
# =====================================================
# ================================================
# API integration options
# ================================================
# The api_key allows your application to authenticate with Panda.
# When a video has been uploaded panda will redirect to upload_redirect_url
# which should exist on your application.
p[:api_key] = "SECRET_KEY_FOR_PANDA_API"
p[:upload_redirect_url] = "http://localhost:4000/videos/$id/done"
# ============================================================
# Local storage. Public should be accessible from the internet
# ============================================================
p[:private_tmp_path] = "/var/tmp/videos"
p[:public_tmp_path] = # '/var/www/images'
p[:public_tmp_url] = # 'http://images.app.com'
# Defaults to tmp within the Panda public directory. Optionally configurable
# p[:public_tmp_path] = "/var/www/images"
# p[:public_tmp_url] = "http://images.app.com"
# ================================================
# Storage location for uploaded and encoded videos
@ -20,28 +28,53 @@ Panda::Config.use do |p|
# For S3 storage:
p[:videos_store] = :s3
# For example "s3.amazonaws.com/myvideosbucket" or a FQDN if configured
p[:videos_domain] = ""
p[:videos_domain] = "s3.amazonaws.com/S3_BUCKET"
p[:s3_videos_bucket] = "S3_BUCKET"
# For local filesystem storage:
# p[:videos_store] = :filesystem
# p[:videos_domain] = "localhost:4000/store"
# p[:public_videos_dir] = Merb.root / "public" / "store"
p[:access_key_id] = "" # Your AWS Access Key
p[:secret_access_key] = "" # Your AWS Secret Access Key
p[:s3_videos_bucket] = "" # eg: "myvideosbucket", or fqdn like "videos.pandastream.com" if you've setup the CNAE record.
p[:sdb_videos_domain] = "panda_videos"
p[:sdb_users_domain] = "panda_users"
p[:sdb_profiles_domain] = "panda_profiles"
# ================================================
# AWS Details
# ================================================
p[:thumbnail_height_constrain] = 125
# Number of thumbnails you can choose from after uploading video.
# If you do not set this value, thumbnail selection will be ignored.
# p[:choose_thumbnail] = 6
# For S3 and SimpleDB:
p[:access_key_id] = "AWS_ACCESS_KEY"
p[:secret_access_key] = "AWS_SECRET_ACCESS_KEY"
p[:notification_retries] = 6 # How many times should a failed notification be retried?
p[:notification_frequency] = 2 # How many
p[:notification_email] = "" # Where notifications get sent to. eg: me@mydomain.com
p[:noreply_from] = "" # Where notifications come from. eg: no-reply@pandastream.com
end
# SimpleDB domains:
p[:sdb_videos_domain] = "PANDA_VIDEOS"
p[:sdb_users_domain] = "PANDA_USERS"
p[:sdb_profiles_domain] = "PANDA_PROFILES"
# ================================================
# Thumbnail
# ================================================
# If you set this option you will be able to change the thumbnail for a
# video after a video has been encoded. This many thumbnail options will
# automatically be generated. The positions of these clipping will be
# equally distributed throughoutt the video.
# p[:choose_thumbnail] = 6
# ================================================
# Application notification
# ================================================
# Panda will send your application a notfication when a video has finished
# encoding. If it fails it will rety notification_retries times. These
# values are the defaults and should work for most applications.
# p[:notification_retries] = 6
# p[:notification_frequency]= 10
p[:state_update_url] = "http://YOUR_APP/videos/$id/status_update"
# ================================================
# Get emailed error messages
# ================================================
# If you want errors emailed to you, when an encoding fails or panda fails
# to post a notification to your application, fill in both values:
# p[:notification_email] = "me@mydomain.com"
# p[:noreply_from] = "panda@mydomain.com"
end

Просмотреть файл

@ -2,6 +2,8 @@ class FileStore < AbstractStore
include FileUtils
def initialize
raise Panda::ConfigError, "You must specify public_videos_dir and videos_domain to use filesystem storage" unless Panda::Config[:public_videos_dir] && Panda::Config[:videos_domain]
@dir = Panda::Config[:public_videos_dir]
mkdir_p(@dir)
end

Просмотреть файл

@ -1,4 +1,5 @@
module Panda
class ConfigError < RuntimeError; end
class Setup
class << self
@ -17,21 +18,16 @@ module Panda
def defaults
@defaults ||= {
:account_name => "My Panda Account",
:api_key => nil,
:notification_email => nil,
:upload_redirect_url => "http://127.0.0.1:3000/videos/$1/done",
:state_update_url => "http://127.0.0.1:3000/videos/$1/status",
:private_tmp_path => "videos",
:private_tmp_path => Merb.root / "videos",
:public_tmp_path => Merb.root / "public" / "tmp",
:public_tmp_url => "/tmp",
:videos_domain => nil,
:storage => :filesystem, # or :s3 TODO: implement
:thumbnail_height_constrain => 126,
:thumbnail_height_constrain => 125,
:choose_thumbnail => false,
:notification_frequency => 3,
:notification_retries => 6
:notification_retries => 6,
:notification_frequency => 10
}
end
@ -47,6 +43,24 @@ module Panda
def []=(key,val)
@configuration[key] = val
end
def check
check_present(:api_key, "Please specify a secret api_key")
check_present(:upload_redirect_url)
check_present(:state_update_url)
%w{sdb_videos_domain sdb_users_domain sdb_profiles_domain}.each do |d|
check_present(d.to_sym)
end
end
def check_present(option, message = nil)
unless Panda::Config[option]
m = "Missing required configuration option: #{option.to_s}"
m += " [#{message}]" if message
raise Panda::ConfigError, m
end
end
end
end
end

Просмотреть файл

@ -1,9 +1,11 @@
class S3VideoObject < AWS::S3::S3Object
set_current_bucket_to Panda::Config[:s3_videos_bucket]
end
class S3Store < AbstractStore
def initialize
raise Panda::ConfigError, "You must specify videos_domain and s3_videos_bucket to use s3 storage" unless Panda::Config[:videos_domain] && Panda::Config[:s3_videos_bucket]
AWS::S3::Base.establish_connection!(
:access_key_id => Panda::Config[:access_key_id],
:secret_access_key => Panda::Config[:secret_access_key],

Просмотреть файл

@ -9,7 +9,7 @@ describe Video do
p[:state_update_url] = "http://localhost:4000/videos/$id/status"
p[:upload_redirect_url] = "http://localhost:4000/videos/$id/done"
p[:videos_domain] = "videos.pandastream.com"
p[:thumbnail_height_constrain] = 126
p[:thumbnail_height_constrain] = 125
end
Store.stub!(:set).and_return(true)