active_encode 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +3 -2
  4. data/Gemfile +35 -0
  5. data/README.md +15 -14
  6. data/Rakefile +5 -10
  7. data/active_encode.gemspec +8 -5
  8. data/app/jobs/active_encode/polling_job.rb +20 -0
  9. data/app/models/active_encode/encode_record.rb +5 -0
  10. data/db/migrate/20180822021048_create_active_encode_encode_records.rb +13 -0
  11. data/lib/active_encode.rb +1 -0
  12. data/lib/active_encode/base.rb +6 -2
  13. data/lib/active_encode/callbacks.rb +18 -35
  14. data/lib/active_encode/core.rb +64 -20
  15. data/lib/active_encode/engine.rb +7 -0
  16. data/lib/active_encode/engine_adapter.rb +2 -2
  17. data/lib/active_encode/engine_adapters/active_job_adapter.rb +7 -3
  18. data/lib/active_encode/engine_adapters/elastic_transcoder_adapter.rb +15 -15
  19. data/lib/active_encode/engine_adapters/inline_adapter.rb +6 -1
  20. data/lib/active_encode/engine_adapters/matterhorn_adapter.rb +18 -18
  21. data/lib/active_encode/engine_adapters/shingoncoder_adapter.rb +13 -9
  22. data/lib/active_encode/engine_adapters/test_adapter.rb +19 -12
  23. data/lib/active_encode/engine_adapters/zencoder_adapter.rb +10 -10
  24. data/lib/active_encode/global_id.rb +16 -0
  25. data/lib/active_encode/input.rb +9 -0
  26. data/lib/active_encode/output.rb +9 -0
  27. data/lib/active_encode/persistence.rb +45 -0
  28. data/lib/active_encode/polling.rb +24 -0
  29. data/lib/active_encode/status.rb +2 -6
  30. data/lib/active_encode/technical_metadata.rb +16 -1
  31. data/lib/active_encode/version.rb +1 -1
  32. data/spec/fixtures/elastic_transcoder/job_canceled.json +1 -1
  33. data/spec/fixtures/elastic_transcoder/job_completed.json +1 -1
  34. data/spec/fixtures/elastic_transcoder/job_created.json +1 -1
  35. data/spec/fixtures/elastic_transcoder/job_failed.json +1 -1
  36. data/spec/fixtures/elastic_transcoder/job_progressing.json +1 -1
  37. data/spec/integration/elastic_transcoder_adapter_spec.rb +87 -167
  38. data/spec/integration/matterhorn_adapter_spec.rb +34 -79
  39. data/spec/integration/shingoncoder_adapter_spec.rb +1 -1
  40. data/spec/integration/zencoder_adapter_spec.rb +1 -1
  41. data/spec/rails_helper.rb +22 -0
  42. data/spec/shared_specs/engine_adapter_specs.rb +124 -0
  43. data/spec/test_app_templates/lib/generators/test_app_generator.rb +15 -0
  44. data/spec/units/callbacks_spec.rb +16 -17
  45. data/spec/units/core_spec.rb +121 -2
  46. data/spec/units/engine_adapter_spec.rb +0 -12
  47. data/spec/units/global_id_spec.rb +49 -0
  48. data/spec/units/input_spec.rb +12 -0
  49. data/spec/units/output_spec.rb +12 -0
  50. data/spec/units/persistence_spec.rb +57 -0
  51. data/spec/units/polling_job_spec.rb +86 -0
  52. data/spec/units/polling_spec.rb +22 -0
  53. data/spec/units/status_spec.rb +21 -2
  54. metadata +89 -20
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveEncode::Input do
4
+ subject { described_class.new }
5
+
6
+ describe 'attributes' do
7
+ it { is_expected.to respond_to(:id, :url) }
8
+ it { is_expected.to respond_to(:state, :errors, :created_at, :updated_at) }
9
+ it { is_expected.to respond_to(:width, :height, :frame_rate, :checksum,
10
+ :audio_codec, :video_codec, :audio_bitrate, :video_bitrate) }
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveEncode::Output do
4
+ subject { described_class.new }
5
+
6
+ describe 'attributes' do
7
+ it { is_expected.to respond_to(:id, :url) }
8
+ it { is_expected.to respond_to(:state, :errors, :created_at, :updated_at) }
9
+ it { is_expected.to respond_to(:width, :height, :frame_rate, :checksum,
10
+ :audio_codec, :video_codec, :audio_bitrate, :video_bitrate) }
11
+ end
12
+ end
@@ -0,0 +1,57 @@
1
+ require 'rails_helper'
2
+
3
+ describe ActiveEncode::Persistence, db_clean: true do
4
+ before do
5
+ class CustomEncode < ActiveEncode::Base
6
+ include ActiveEncode::Persistence
7
+ end
8
+ end
9
+
10
+ after do
11
+ Object.send(:remove_const, :CustomEncode)
12
+ end
13
+
14
+ describe 'find' do
15
+ let(:encode) { CustomEncode.create(nil) }
16
+ subject { ActiveEncode::EncodeRecord.find_by(global_id: encode.to_global_id.to_s) }
17
+
18
+ it 'persists changes on find' do
19
+ expect { CustomEncode.find(encode.id) }.to change { subject.reload.updated_at }
20
+ end
21
+ end
22
+
23
+ describe 'create' do
24
+ let(:encode) { CustomEncode.create(nil) }
25
+ subject { ActiveEncode::EncodeRecord.find_by(global_id: encode.to_global_id.to_s) }
26
+
27
+ it 'creates a record' do
28
+ expect { encode }.to change { ActiveEncode::EncodeRecord.count }.by(1)
29
+ end
30
+
31
+ its(:global_id) { is_expected.to eq encode.to_global_id.to_s }
32
+ its(:state) { is_expected.to eq encode.state.to_s }
33
+ its(:adapter) { is_expected.to eq encode.class.engine_adapter.class.name }
34
+ its(:title) { is_expected.to eq encode.input.url.to_s }
35
+ its(:raw_object) { is_expected.to eq encode.to_json }
36
+ its(:created_at) { is_expected.to be_within(1.second).of encode.created_at }
37
+ its(:updated_at) { is_expected.to be_within(1.second).of encode.updated_at }
38
+ end
39
+
40
+ describe 'cancel' do
41
+ let(:encode) { CustomEncode.create(nil) }
42
+ subject { ActiveEncode::EncodeRecord.find_by(global_id: encode.to_global_id.to_s) }
43
+
44
+ it 'persists changes on cancel' do
45
+ expect { encode.cancel! }.to change { subject.reload.state }.from("running").to("cancelled")
46
+ end
47
+ end
48
+
49
+ describe 'reload' do
50
+ let(:encode) { CustomEncode.create(nil) }
51
+ subject { ActiveEncode::EncodeRecord.find_by(global_id: encode.to_global_id.to_s) }
52
+
53
+ it 'persists changes on reload' do
54
+ expect { encode.reload }.to change { subject.reload.updated_at }
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,86 @@
1
+ require 'rails_helper'
2
+
3
+ describe ActiveEncode::PollingJob do
4
+ include ActiveJob::TestHelper
5
+
6
+ before do
7
+ class PollingEncode < ActiveEncode::Base
8
+ include ActiveEncode::Polling
9
+ after_status_update ->(encode) { encode.history << "PollingEncode ran after_status_update" }
10
+ after_error ->(encode) { encode.history << "PollingEncode ran after_error" }
11
+ after_cancelled ->(encode) { encode.history << "PollingEncode ran after_cancelled" }
12
+ after_complete ->(encode) { encode.history << "PollingEncode ran after_complete" }
13
+
14
+ def history
15
+ @history ||= []
16
+ end
17
+ end
18
+ end
19
+
20
+ after do
21
+ Object.send(:remove_const, :PollingEncode)
22
+ end
23
+
24
+ describe '#perform' do
25
+ let(:encode) { PollingEncode.create("sample.mp4").tap { |encode| encode.state = state } }
26
+ let(:poll) { ActiveEncode::PollingJob.new }
27
+ subject { encode.history }
28
+
29
+ before do
30
+ encode
31
+ clear_enqueued_jobs
32
+ poll.perform(encode)
33
+ end
34
+
35
+ context "with job in error" do
36
+ let(:state) { :error }
37
+
38
+ it "runs after_error" do
39
+ is_expected.to include("PollingEncode ran after_status_update")
40
+ is_expected.to include("PollingEncode ran after_error")
41
+ end
42
+
43
+ it "does not re-enqueue itself" do
44
+ expect(ActiveEncode::PollingJob).not_to have_been_enqueued
45
+ end
46
+ end
47
+
48
+ context "with job cancelled" do
49
+ let(:state) { :cancelled }
50
+
51
+ it "runs after_cancelled" do
52
+ is_expected.to include("PollingEncode ran after_status_update")
53
+ is_expected.to include("PollingEncode ran after_cancelled")
54
+ end
55
+
56
+ it "does not re-enqueue itself" do
57
+ expect(ActiveEncode::PollingJob).not_to have_been_enqueued
58
+ end
59
+ end
60
+
61
+ context "with job complete" do
62
+ let(:state) { :complete }
63
+
64
+ it "runs after_complete" do
65
+ is_expected.to include("PollingEncode ran after_status_update")
66
+ is_expected.to include("PollingEncode ran after_complete")
67
+ end
68
+
69
+ it "does not re-enqueue itself" do
70
+ expect(ActiveEncode::PollingJob).not_to have_been_enqueued
71
+ end
72
+ end
73
+
74
+ context "with job running" do
75
+ let(:state) { :running }
76
+
77
+ it "runs after_status_update" do
78
+ is_expected.to include("PollingEncode ran after_status_update")
79
+ end
80
+
81
+ it "re-enqueues itself" do
82
+ expect(ActiveEncode::PollingJob).to have_been_enqueued.with(encode)
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,22 @@
1
+ require 'rails_helper'
2
+
3
+ describe ActiveEncode::Polling do
4
+ before do
5
+ class PollingEncode < ActiveEncode::Base
6
+ include ActiveEncode::Polling
7
+ end
8
+ end
9
+
10
+ after do
11
+ Object.send(:remove_const, :PollingEncode)
12
+ end
13
+
14
+ describe 'after_create' do
15
+ subject { PollingEncode.create("sample.mp4") }
16
+
17
+ it "enqueues a PollingJob" do
18
+ subject
19
+ expect(ActiveEncode::PollingJob).to have_been_enqueued.with(subject)
20
+ end
21
+ end
22
+ end
@@ -1,10 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveEncode::Status do
4
- subject { ActiveEncode::Base.new(nil) }
4
+ before do
5
+ class CustomEncode < ActiveEncode::Base
6
+ end
7
+ end
8
+ after do
9
+ Object.send(:remove_const, :CustomEncode)
10
+ end
11
+
12
+ let(:encode_class) { ActiveEncode::Base }
13
+
14
+ subject { encode_class.new(nil) }
15
+
16
+ describe 'attributes' do
17
+ it { is_expected.to respond_to(:state, :errors, :created_at, :updated_at) }
18
+
19
+ context 'with an ActiveEncode::Base subclass' do
20
+ let(:encode_class) { CustomEncode }
21
+
22
+ it { is_expected.to respond_to(:state, :errors, :created_at, :updated_at) }
23
+ end
24
+ end
5
25
 
6
26
  context 'new object' do
7
- subject { ActiveEncode::Base.new(nil) }
8
27
  it { is_expected.not_to be_created }
9
28
  it { is_expected.not_to be_running }
10
29
  it { is_expected.not_to be_cancelled }
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_encode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klein, Chris Colvard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-13 00:00:00.000000000 Z
11
+ date: 2018-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.7'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.7'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: coveralls
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,48 +52,90 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: database_cleaner
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: engine_cart
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rake
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - "~>"
87
+ - - ">="
60
88
  - !ruby/object:Gem::Version
61
- version: '10.0'
89
+ version: '0'
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - "~>"
94
+ - - ">="
67
95
  - !ruby/object:Gem::Version
68
- version: '10.0'
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rspec
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
- - - "~>"
101
+ - - ">="
74
102
  - !ruby/object:Gem::Version
75
- version: '3.0'
103
+ version: '0'
76
104
  type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
- - - "~>"
108
+ - - ">="
81
109
  - !ruby/object:Gem::Version
82
- version: '3.0'
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: rspec-its
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
- - - "~>"
115
+ - - ">="
88
116
  - !ruby/object:Gem::Version
89
- version: '1.2'
117
+ version: '0'
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
- - - "~>"
122
+ - - ">="
95
123
  - !ruby/object:Gem::Version
96
- version: '1.2'
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec-rails
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
97
139
  description: This gem serves as the basis for the interface between a Ruby (Rails)
98
140
  application and a provider of transcoding services such as Opencast Matterhorn,
99
141
  Zencoder, and Amazon Elastic Transcoder.
@@ -113,10 +155,14 @@ files:
113
155
  - README.md
114
156
  - Rakefile
115
157
  - active_encode.gemspec
158
+ - app/jobs/active_encode/polling_job.rb
159
+ - app/models/active_encode/encode_record.rb
160
+ - db/migrate/20180822021048_create_active_encode_encode_records.rb
116
161
  - lib/active_encode.rb
117
162
  - lib/active_encode/base.rb
118
163
  - lib/active_encode/callbacks.rb
119
164
  - lib/active_encode/core.rb
165
+ - lib/active_encode/engine.rb
120
166
  - lib/active_encode/engine_adapter.rb
121
167
  - lib/active_encode/engine_adapters.rb
122
168
  - lib/active_encode/engine_adapters/active_job_adapter.rb
@@ -126,6 +172,11 @@ files:
126
172
  - lib/active_encode/engine_adapters/shingoncoder_adapter.rb
127
173
  - lib/active_encode/engine_adapters/test_adapter.rb
128
174
  - lib/active_encode/engine_adapters/zencoder_adapter.rb
175
+ - lib/active_encode/global_id.rb
176
+ - lib/active_encode/input.rb
177
+ - lib/active_encode/output.rb
178
+ - lib/active_encode/persistence.rb
179
+ - lib/active_encode/polling.rb
129
180
  - lib/active_encode/status.rb
130
181
  - lib/active_encode/technical_metadata.rb
131
182
  - lib/active_encode/version.rb
@@ -167,10 +218,19 @@ files:
167
218
  - spec/integration/matterhorn_adapter_spec.rb
168
219
  - spec/integration/shingoncoder_adapter_spec.rb
169
220
  - spec/integration/zencoder_adapter_spec.rb
221
+ - spec/rails_helper.rb
222
+ - spec/shared_specs/engine_adapter_specs.rb
170
223
  - spec/spec_helper.rb
224
+ - spec/test_app_templates/lib/generators/test_app_generator.rb
171
225
  - spec/units/callbacks_spec.rb
172
226
  - spec/units/core_spec.rb
173
227
  - spec/units/engine_adapter_spec.rb
228
+ - spec/units/global_id_spec.rb
229
+ - spec/units/input_spec.rb
230
+ - spec/units/output_spec.rb
231
+ - spec/units/persistence_spec.rb
232
+ - spec/units/polling_job_spec.rb
233
+ - spec/units/polling_spec.rb
174
234
  - spec/units/status_spec.rb
175
235
  homepage: ''
176
236
  licenses:
@@ -192,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
252
  version: '0'
193
253
  requirements: []
194
254
  rubyforge_project:
195
- rubygems_version: 2.5.1
255
+ rubygems_version: 2.6.14
196
256
  signing_key:
197
257
  specification_version: 4
198
258
  summary: Declare encode job classes that can be run by a variety of encoding services
@@ -235,8 +295,17 @@ test_files:
235
295
  - spec/integration/matterhorn_adapter_spec.rb
236
296
  - spec/integration/shingoncoder_adapter_spec.rb
237
297
  - spec/integration/zencoder_adapter_spec.rb
298
+ - spec/rails_helper.rb
299
+ - spec/shared_specs/engine_adapter_specs.rb
238
300
  - spec/spec_helper.rb
301
+ - spec/test_app_templates/lib/generators/test_app_generator.rb
239
302
  - spec/units/callbacks_spec.rb
240
303
  - spec/units/core_spec.rb
241
304
  - spec/units/engine_adapter_spec.rb
305
+ - spec/units/global_id_spec.rb
306
+ - spec/units/input_spec.rb
307
+ - spec/units/output_spec.rb
308
+ - spec/units/persistence_spec.rb
309
+ - spec/units/polling_job_spec.rb
310
+ - spec/units/polling_spec.rb
242
311
  - spec/units/status_spec.rb