staugaard-transcoding_machine 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 0
2
+ :patch: 1
3
3
  :major: 0
4
4
  :minor: 1
@@ -4,13 +4,12 @@ require 'transcoding_machine/server/s3_storage'
4
4
  module TranscodingMachine
5
5
  module Client
6
6
  class JobQueue
7
- def initialize
8
- @sqs = RightAws::SqsGen2.new
9
- end
10
-
11
- def push(queue_name, bucket, key, media_player_ids, result_queue_name)
12
- msg = {:bucket => bucket, :key => key, :media_players => media_player_ids, :result_queue => result_queue_name}
13
- @sqs.queue(queue_name).push(msg.to_yaml)
7
+ def self.push(queue_name, bucket, key, media_player_ids, result_queue_name, options = {})
8
+ options[:bucket] = bucket
9
+ options[:key] = key
10
+ options[:media_players] = media_player_ids
11
+ options[:result_queue] = result_queue_name
12
+ RightAws::SqsGen2.new.queue(queue_name).push(options.to_yaml)
14
13
  end
15
14
  end
16
15
  end
@@ -33,7 +33,6 @@ module TranscodingMachine
33
33
 
34
34
  def consume_message(message, &block)
35
35
  message_properties = YAML.load(message.body)
36
- puts "consuming message #{message_properties.inspect}"
37
36
 
38
37
  begin
39
38
  yield(message_properties)
@@ -21,7 +21,7 @@ module TranscodingMachine
21
21
  end
22
22
 
23
23
  def analyzed_source_file(source_file_attributes, source_media_format)
24
- push_status(:analyzed, :media_format => source_media_format, :media_attributes => source_file_attributes)
24
+ push_status(:analyzed, :media_format => source_media_format.id, :media_attributes => source_file_attributes)
25
25
  end
26
26
 
27
27
  def generating_thumbnail_file
@@ -29,23 +29,23 @@ module TranscodingMachine
29
29
  end
30
30
 
31
31
  def generated_thumbnail_file
32
-
32
+ push_status(:created_thumbnail)
33
33
  end
34
34
 
35
35
  def transcoding(media_format)
36
- push_status(:transcoding, :media_format => media_format)
36
+ push_status(:transcoding, :media_format => media_format.id)
37
37
  end
38
38
 
39
39
  def transcoded(media_format)
40
- push_status(:transcoded, :media_format => media_format)
40
+ push_status(:transcoded, :media_format => media_format.id)
41
41
  end
42
42
 
43
43
  def putting_destination_file(file_path, media_format)
44
- push_status(:uploading, :media_format => media_format, :destination_key => file_path)
44
+ push_status(:uploading, :media_format => media_format.id, :destination_key => file_path)
45
45
  end
46
46
 
47
47
  def put_destination_file(file_path, media_format)
48
- push_status(:uploaded, :media_format => media_format, :destination_key => file_path)
48
+ push_status(:uploaded, :media_format => media_format.id, :destination_key => file_path)
49
49
  end
50
50
 
51
51
  def push_status(status, options = {})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: staugaard-transcoding_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mick Staugaard
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-03 00:00:00 -07:00
12
+ date: 2009-04-07 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 1.10.0
43
+ version: 1.9.0
44
44
  version:
45
45
  description: TODO
46
46
  email: mick@staugaard.com
@@ -61,7 +61,6 @@ files:
61
61
  - lib/transcoding_machine/client
62
62
  - lib/transcoding_machine/client/job_queue.rb
63
63
  - lib/transcoding_machine/client/result_queue.rb
64
- - lib/transcoding_machine/client/server_manager.rb
65
64
  - lib/transcoding_machine/media_format.rb
66
65
  - lib/transcoding_machine/media_format_criterium.rb
67
66
  - lib/transcoding_machine/media_player.rb
@@ -1,107 +0,0 @@
1
- require 'right_aws'
2
-
3
- module TranscodingMachine
4
- module Client
5
- class ServerManager
6
-
7
- # Sets up a new ServerManager
8
- # queue_settings are a in the following format:
9
- # {'transcoding_job_queue' => {:ami => 'ami-e444444d',
10
- # :location => 'us-east-1c',
11
- # :key => 'my_awesome_key',
12
- # :type => 'm1.large'}
13
- # }
14
- #
15
- # options are:
16
- # * <tt>:sleep_time</tt> the time to sleep between queue checks (default 30)
17
- # * <tt>:transcoding_settings</tt> a string or lambda with the userdata to send to new transcoding servers
18
- # * <tt>:server_count</tt> a lambda returning the needed number of transcoding servers for a given queue (defaults to the queue size)
19
- def initialize(queue_settings, options)
20
- @sqs = RightAws::SqsGen2.new
21
- @ec2 = RightAws::Ec2.new
22
-
23
- @queues = Hash.new
24
- queue_settings.each do |queue_name, settings|
25
- @queues[@sqs.queue(queue_name.to_s)] = settings
26
- end
27
-
28
- @server_count = options[:server_count] || lambda {|queue| queue.size}
29
-
30
- @transcoding_settings = options[:transcoding_settings]
31
-
32
- @sleep_time = options[:sleep_time] || 20
33
-
34
- @running = false
35
- end
36
-
37
- def needed_server_count(queue)
38
- @server_count.call(queue)
39
- end
40
-
41
- def transcoding_settings(queue)
42
- "test"
43
- #@transcoding_settings.respond_to?(:call) ? @transcoding_settings.call(queue) : @transcoding_settings
44
- end
45
-
46
- def running_server_count(queue)
47
- @ec2.describe_instances.find_all do |instance|
48
- state = instance[:aws_state_code].to_i
49
- zone = instance[:aws_availability_zone]
50
- ami = instance[:aws_image_id]
51
-
52
- matches = state <= 16
53
- matches &&= ami == ec2_ami(queue)
54
- matches &&= zone == ec2_location(queue) if ec2_location(queue)
55
- matches
56
- end.size
57
- end
58
-
59
- def ec2_ami(queue)
60
- @queues[queue][:ami]
61
- end
62
-
63
- def ec2_location(queue)
64
- @queues[queue][:location]
65
- end
66
-
67
- def ec2_key(queue)
68
- @queues[queue][:key]
69
- end
70
-
71
- def ec2_instance_type(queue)
72
- @queues[queue][:type]
73
- end
74
-
75
- def ec2_security_groups(queue)
76
- @queues[queue][:security_groups]
77
- end
78
-
79
- def manage_servers(options = {})
80
- @running = true
81
-
82
- while @running
83
- @queues.keys.each do |queue|
84
- needed = needed_server_count(queue)
85
- running = running_server_count(queue)
86
-
87
- #if needed > 0 || running > 0
88
- puts "#{running} of #{needed} needed servers are running for queue #{queue.name}"
89
- #end
90
-
91
- if running < needed
92
- puts "requesting #{needed - running} new servers for queue #{queue.name}"
93
- puts [ec2_ami(queue), 1, needed - running, ec2_security_groups(queue),
94
- ec2_key(queue), transcoding_settings(queue),
95
- nil, ec2_instance_type(queue), nil, nil, ec2_location(queue)].inspect
96
-
97
- new_servers = @ec2.run_instances(ec2_ami(queue), 1, needed - running, ec2_security_groups(queue),
98
- ec2_key(queue), transcoding_settings(queue),
99
- nil, ec2_instance_type(queue), nil, nil, ec2_location(queue))
100
- end
101
- end
102
- sleep(@sleep_time)
103
- end
104
- end
105
- end
106
- end
107
- end