module MovieMasher
Handles global configuration and high level processing of Job
objects. The ::process_queues
method will look for jobs in a directory and optionally an SQS queue for a period of time, calling ::process
for each one found. No configuration is required, though be aware that no download cache is maintained by default.
MovieMasher.configure render_directory: './temp' MovieMasher.process './job.json' # => #<MovieMasher::Job:0x007fa34300abc0>
Constants
- VERSION
Attributes
Public Class Methods
- hash_or_path
-
Set one or more configuration options. If supplied a String, it's assumed to be a path to a JSON or YML file and converted to a Hash. The Hash can use a String or Symbol for each key. See Config for supported keys.
Returns¶ ↑
Returns nothing.
Raises Error::Configuration
if String supplied doesn't have json/yml extension or if render_directory is empty.
# File lib/moviemasher.rb, line 46 def configure(hash_or_path = nil) MovieMasher.__config ||= Configuration::DEFAULTS.dup if hash_or_path && !hash_or_path.empty? if hash_or_path.is_a?(String) hash_or_path = __configuration_from_file(hash_or_path) end if hash_or_path.is_a?(Hash) && !hash_or_path.empty? hash_or_path.each do |key_str, v| next if v.to_s.empty? key_str = key_str.to_sym if key_str.respond_to?(:to_sym) MovieMasher.__config[key_str] = v end end end __configure_directories Service.configure_services(MovieMasher.__config) MovieMasher.__config end
- object_or_path
-
Job
object or String/Hash to be passed toJob.new
along with::configuration
. After theMovieMasher::Job#process
method is called, its render directory is either moved to error_directory (if that option isnot empty and a problem arose during processing) or deleted (unless render_save is true). The download_directory will also be pruned to assure its size is not greater than download_bytes.
Returns¶ ↑
Returns Job
object with error key set if problem arose.
Raises Error::Configuration
if render_directory is empty.
# File lib/moviemasher.rb, line 85 def process(object_or_path) object_or_path = Job.new(object_or_path) unless object_or_path.is_a?(Job) result = MovieMasher.__job = object_or_path # try to process job begin MovieMasher.__job.process unless MovieMasher.__job[:error] rescue StandardError => e __log_exception(e) end # try to move or remove job's render directory begin job_dir = Path.concat( configuration[:render_directory], result.identifier ) if File.directory?(job_dir) if result[:error] && !configuration[:error_directory].to_s.empty? FileUtils.mv(job_dir, configuration[:error_directory]) else FileUtils.rm_r(job_dir) unless configuration[:render_save] end end rescue StandardError => e __log_exception(e) ensure MovieMasher.__job = nil end __flush result # what was MovieMasher.__job end
Calls process for each item in array of job strings or paths
# File lib/moviemasher.rb, line 117 def process_jobs(array) array.each do |job_str| process job_str end (array.empty? ? nil : array.length) end
Searches configured queue(s) for job(s) and processes.
- process_seconds
-
overrides this same configuration option. A positive value will cause the method to loop that many seconds, while a value of zero will cause it to immediately return without searching for a job. A value of -1 indicates that each queue should be searched just once for a job, and -2will loop until no queue returns a job. And finally, -3 will cause the method to loop forever.
This method should not raise an Exception, but if it does it is not trapped here so queue processing will stop.
Returns¶ ↑
Returns nothing.
Raises Error::Configuration
if queue_directory or render_directory is empty.
# File lib/moviemasher.rb, line 140 def process_queues(process_seconds = nil) process_seconds ||= configuration[:process_seconds] process_seconds = process_seconds.to_i __log_process(process_seconds) start = Time.now while process_seconds.negative? || (process_seconds > (Time.now - start)) found = false Service.queues.each do |queue| job_data = queue.receive_job next unless job_data found = true __log_transcoder(:debug) { "starting #{job_data[:id]}" } process(job_data) __log_transcoder(:debug) { "finishing #{job_data[:id]}" } break end break if process_seconds == -1 break if process_seconds == -2 && !found sleep(0.01) end end