fogged 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/fogged/resources_controller.rb +22 -1
- data/app/models/fogged/resources/aws_encoder.rb +25 -17
- data/config/routes.rb +4 -2
- data/lib/fogged.rb +2 -2
- data/lib/fogged/version.rb +1 -1
- data/test/controllers/fogged/resources_controller/confirm_test.rb +1 -5
- data/test/controllers/fogged/resources_controller/zencoder_notification_test.rb +74 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +12298 -0
- data/test/models/fogged/resource_test.rb +2 -3
- data/test/models/fogged/resources/aws_encoder_test.rb +25 -9
- metadata +4 -5
- data/app/jobs/fogged/resources/zencoder_poll_job.rb +0 -37
- data/test/jobs/fogged/resources/zencoder_poll_job_test.rb +0 -96
@@ -77,9 +77,8 @@ module Fogged
|
|
77
77
|
OpenStruct.new(:body => create_output)
|
78
78
|
)
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
end
|
80
|
+
@resource.process!
|
81
|
+
|
83
82
|
assert @resource.encoding?
|
84
83
|
assert_equal "1234567890", @resource.encoding_job_id
|
85
84
|
end
|
@@ -40,15 +40,12 @@ module Fogged
|
|
40
40
|
in_a_fork do
|
41
41
|
require "zencoder"
|
42
42
|
require "delayed_job_active_record"
|
43
|
-
Rails.application.config.active_job.queue_adapter = :delayed_job
|
44
43
|
Fogged.configure
|
45
44
|
|
46
45
|
Zencoder::Job.expects(:create).returns(
|
47
46
|
OpenStruct.new(:body => create_output)
|
48
47
|
)
|
49
|
-
|
50
|
-
encoder.encode!
|
51
|
-
end
|
48
|
+
encoder.encode!
|
52
49
|
|
53
50
|
assert resource.encoding?
|
54
51
|
assert_equal 0, resource.encoding_progress
|
@@ -110,7 +107,6 @@ module Fogged
|
|
110
107
|
in_a_fork do
|
111
108
|
require "zencoder"
|
112
109
|
require "delayed_job_active_record"
|
113
|
-
Rails.application.config.active_job.queue_adapter = :delayed_job
|
114
110
|
Fogged.configure do |config|
|
115
111
|
config.zencoder_additional_outputs do |bucket, res|
|
116
112
|
[
|
@@ -124,12 +120,32 @@ module Fogged
|
|
124
120
|
end
|
125
121
|
end
|
126
122
|
|
127
|
-
Zencoder::Job.expects(:create).with { |options| assert_equal 4, options[:output].size }.returns(
|
123
|
+
Zencoder::Job.expects(:create).with() { |options| assert_equal 4, options[:output].size }.returns(
|
128
124
|
OpenStruct.new(:body => create_output)
|
129
125
|
)
|
130
|
-
|
131
|
-
|
132
|
-
|
126
|
+
encoder.encode!
|
127
|
+
|
128
|
+
assert resource.encoding?
|
129
|
+
assert_equal 0, resource.encoding_progress
|
130
|
+
assert_equal "1234567890", resource.encoding_job_id
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
test "should encode video with zencoder notification url" do
|
135
|
+
resource = fogged_resources(:resource_mov_3)
|
136
|
+
encoder = AWSEncoder.new(resource)
|
137
|
+
|
138
|
+
in_a_fork do
|
139
|
+
require "zencoder"
|
140
|
+
require "delayed_job_active_record"
|
141
|
+
Fogged.configure
|
142
|
+
Fogged.stubs(:zencoder_notification_url).returns("http://test")
|
143
|
+
|
144
|
+
Zencoder::Job.expects(:create).with() { |options| assert options[:notifications] }.returns(
|
145
|
+
OpenStruct.new(:body => create_output)
|
146
|
+
)
|
147
|
+
|
148
|
+
encoder.encode!
|
133
149
|
|
134
150
|
assert resource.encoding?
|
135
151
|
assert_equal 0, resource.encoding_progress
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fogged
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Fernandez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -189,7 +189,6 @@ files:
|
|
189
189
|
- Rakefile
|
190
190
|
- app/controllers/fogged/resources_controller.rb
|
191
191
|
- app/jobs/fogged/resources/aws_thumbnail_job.rb
|
192
|
-
- app/jobs/fogged/resources/zencoder_poll_job.rb
|
193
192
|
- app/models/fogged/resource.rb
|
194
193
|
- app/models/fogged/resources/aws_encoder.rb
|
195
194
|
- app/models/fogged/resources/encoder.rb
|
@@ -214,6 +213,7 @@ files:
|
|
214
213
|
- test/controllers/fogged/resources_controller/destroy_test.rb
|
215
214
|
- test/controllers/fogged/resources_controller/show_test.rb
|
216
215
|
- test/controllers/fogged/resources_controller/update_test.rb
|
216
|
+
- test/controllers/fogged/resources_controller/zencoder_notification_test.rb
|
217
217
|
- test/dummy/Rakefile
|
218
218
|
- test/dummy/app/assets/javascripts/application.js
|
219
219
|
- test/dummy/app/assets/stylesheets/application.css
|
@@ -270,7 +270,6 @@ files:
|
|
270
270
|
- test/fixtures/movies.yml
|
271
271
|
- test/fogged_test.rb
|
272
272
|
- test/jobs/fogged/resources/aws_thumbnail_job_test.rb
|
273
|
-
- test/jobs/fogged/resources/zencoder_poll_job_test.rb
|
274
273
|
- test/models/fogged/resource_test.rb
|
275
274
|
- test/models/fogged/resources/aws_encoder_test.rb
|
276
275
|
- test/models/fogged/resources/encoder_test.rb
|
@@ -307,6 +306,7 @@ test_files:
|
|
307
306
|
- test/controllers/fogged/resources_controller/destroy_test.rb
|
308
307
|
- test/controllers/fogged/resources_controller/show_test.rb
|
309
308
|
- test/controllers/fogged/resources_controller/update_test.rb
|
309
|
+
- test/controllers/fogged/resources_controller/zencoder_notification_test.rb
|
310
310
|
- test/dummy/app/assets/javascripts/application.js
|
311
311
|
- test/dummy/app/assets/stylesheets/application.css
|
312
312
|
- test/dummy/app/controllers/application_controller.rb
|
@@ -363,7 +363,6 @@ test_files:
|
|
363
363
|
- test/fixtures/movies.yml
|
364
364
|
- test/fogged_test.rb
|
365
365
|
- test/jobs/fogged/resources/aws_thumbnail_job_test.rb
|
366
|
-
- test/jobs/fogged/resources/zencoder_poll_job_test.rb
|
367
366
|
- test/models/fogged/resource_test.rb
|
368
367
|
- test/models/fogged/resources/aws_encoder_test.rb
|
369
368
|
- test/models/fogged/resources/encoder_test.rb
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module Fogged
|
2
|
-
module Resources
|
3
|
-
class ZencoderPollJob < ActiveJob::Base
|
4
|
-
def perform(resource)
|
5
|
-
return unless Fogged.zencoder_enabled
|
6
|
-
update_encoding_progress(resource)
|
7
|
-
|
8
|
-
return if resource.encoding_progress == 100
|
9
|
-
|
10
|
-
frequency = Fogged.zencoder_polling_frequency
|
11
|
-
retry_job(:wait => frequency.seconds)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def update_encoding_progress(resource)
|
17
|
-
job = Zencoder::Job.progress(resource.encoding_job_id)
|
18
|
-
|
19
|
-
case job.body["state"]
|
20
|
-
when "finished"
|
21
|
-
job = Zencoder::Job.details(resource.encoding_job_id)
|
22
|
-
f = job.body["job"]["output_media_files"][0]
|
23
|
-
resource.update!(
|
24
|
-
:encoding_progress => 100,
|
25
|
-
:width => f["width"],
|
26
|
-
:height => f["height"],
|
27
|
-
:duration => f["duration_in_ms"].to_f / 1000.0
|
28
|
-
)
|
29
|
-
when "processing", "waiting"
|
30
|
-
resource.update!(:encoding_progress => job.body["progress"].to_i)
|
31
|
-
else
|
32
|
-
fail(ArgumentError, "Unknown Zencoder job state #{job.body["state"]}")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
module Fogged
|
4
|
-
module Resources
|
5
|
-
class ZencoderPollJobTest < ActiveSupport::TestCase
|
6
|
-
def setup
|
7
|
-
super
|
8
|
-
@resource = fogged_resources(:encoding_resource)
|
9
|
-
end
|
10
|
-
|
11
|
-
test "should poll job with status success" do
|
12
|
-
in_a_fork do
|
13
|
-
require "zencoder"
|
14
|
-
require "delayed_job_active_record"
|
15
|
-
Rails.application.config.active_job.queue_adapter = :delayed_job
|
16
|
-
Fogged.configure
|
17
|
-
|
18
|
-
Zencoder::Job.expects(:progress).with("1234567890").returns(
|
19
|
-
OpenStruct.new(:body => progress_output("finished"))
|
20
|
-
)
|
21
|
-
Zencoder::Job.expects(:details).with("1234567890").returns(
|
22
|
-
OpenStruct.new(:body => details_output)
|
23
|
-
)
|
24
|
-
|
25
|
-
assert_no_difference("Delayed::Job.count") do
|
26
|
-
ZencoderPollJob.perform_now(@resource)
|
27
|
-
end
|
28
|
-
refute @resource.reload.encoding?
|
29
|
-
assert_equal 800, @resource.width
|
30
|
-
assert_equal 600, @resource.height
|
31
|
-
assert_equal 15, @resource.duration
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
%w(processing waiting).each do |status|
|
36
|
-
test "should poll job with status #{status}" do
|
37
|
-
in_a_fork do
|
38
|
-
require "zencoder"
|
39
|
-
require "delayed_job_active_record"
|
40
|
-
Rails.application.config.active_job.queue_adapter = :delayed_job
|
41
|
-
Fogged.configure
|
42
|
-
|
43
|
-
Zencoder::Job.expects(:progress).with("1234567890").returns(
|
44
|
-
OpenStruct.new(:body => progress_output(status))
|
45
|
-
)
|
46
|
-
|
47
|
-
assert_difference("Delayed::Job.count") do
|
48
|
-
ZencoderPollJob.perform_now(@resource)
|
49
|
-
end
|
50
|
-
assert @resource.reload.encoding?
|
51
|
-
assert_equal 55, @resource.encoding_progress
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
test "should poll job with status unknown" do
|
57
|
-
in_a_fork do
|
58
|
-
require "zencoder"
|
59
|
-
require "delayed_job_active_record"
|
60
|
-
Fogged.configure
|
61
|
-
|
62
|
-
Zencoder::Job.expects(:progress).with("1234567890").returns(
|
63
|
-
OpenStruct.new(:body => progress_output("unknown"))
|
64
|
-
)
|
65
|
-
|
66
|
-
assert_raise(ArgumentError) do
|
67
|
-
assert_no_difference("Delayed::Job.count") do
|
68
|
-
ZencoderPollJob.perform_now(@resource)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
private
|
75
|
-
|
76
|
-
def progress_output(state)
|
77
|
-
{
|
78
|
-
:state => state,
|
79
|
-
:progress => "55.5"
|
80
|
-
}.with_indifferent_access
|
81
|
-
end
|
82
|
-
|
83
|
-
def details_output
|
84
|
-
{
|
85
|
-
:job => {
|
86
|
-
:output_media_files => [{
|
87
|
-
:width => 800,
|
88
|
-
:height => 600,
|
89
|
-
:duration_in_ms => 15753
|
90
|
-
}]
|
91
|
-
}
|
92
|
-
}.with_indifferent_access
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|