Skip to content

Commit d95ce45

Browse files
committed
Add timestamp methods to encode
1 parent 7c461a9 commit d95ce45

5 files changed

Lines changed: 61 additions & 3 deletions

File tree

lib/active_encode/engine_adapters/matterhorn_adapter.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ def build_encode(workflow, cast)
8686
encode.state = convert_state(workflow)
8787
encode.current_operations = convert_current_operations(workflow)
8888
encode.percent_complete = calculate_percent_complete(workflow)
89+
encode.created_at = convert_created_at(workflow)
90+
encode.updated_at = convert_updated_at(workflow)
91+
encode.finished_at = convert_finished_at(workflow) unless encode.running?
8992
encode.output = convert_output(workflow, encode.options)
9093
encode.errors = convert_errors(workflow)
9194
encode.tech_metadata = convert_tech_metadata(workflow)
@@ -141,6 +144,21 @@ def convert_errors(workflow)
141144
workflow.xpath('//errors/error/text()').map(&:to_s)
142145
end
143146

147+
def convert_created_at(workflow)
148+
created_at = workflow.xpath('mediapackage/@start').last.to_s
149+
created_at.present? ? Time.parse(created_at).iso8601 : nil
150+
end
151+
152+
def convert_updated_at(workflow)
153+
updated_at = workflow.xpath('//operation[@state!="INSTANTIATED"]/completed/text()').last.to_s
154+
updated_at.present? ? Time.strptime(updated_at, "%Q").utc.iso8601 : nil
155+
end
156+
157+
def convert_finished_at(workflow)
158+
finished_at = workflow.xpath('//operation[@state!="INSTANTIATED"]/completed/text()').last.to_s
159+
finished_at.present? ? Time.strptime(finished_at, "%Q").utc.iso8601 : nil
160+
end
161+
144162
def convert_options(workflow)
145163
options = {}
146164
options[:preset] = workflow.xpath('template/text()').to_s

lib/active_encode/engine_adapters/zencoder_adapter.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def build_encode(job_details, cast)
4646
job_progress = get_job_progress(encode.id)
4747
encode.current_operations = convert_current_operations(job_progress)
4848
encode.percent_complete = convert_percent_complete(job_progress, job_details)
49+
encode.created_at = job_details.body["job"]["created_at"]
50+
encode.updated_at = job_details.body["job"]["updated_at"]
51+
encode.finished_at = job_details.body["job"]["finished_at"]
4952
encode.output = convert_output(job_details)
5053
encode.errors = convert_errors(job_details)
5154
encode.tech_metadata = convert_tech_metadata(job_details.body["job"]["input_media_file"])

lib/active_encode/status.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ module Status
77
included do
88
# Current state of the encoding process
99
attr_accessor :state
10-
1110
attr_accessor :current_operations
12-
1311
attr_accessor :percent_complete
14-
1512
attr_accessor :errors
13+
14+
attr_accessor :created_at
15+
attr_accessor :finished_at
16+
attr_accessor :updated_at
1617
end
1718

1819
def created?

spec/integration/matterhorn_adapter_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
its(:current_operations) { is_expected.to be_empty }
2929
its(:percent_complete) { is_expected.to eq 0 }
3030
its(:errors) { is_expected.to be_empty }
31+
its(:created_at) { is_expected.to eq '2015-04-24T15:44:47Z' }
32+
its(:updated_at) { is_expected.to be_nil }
33+
its(:finished_at) { is_expected.to be_nil }
3134
its(:tech_metadata) { is_expected.to be_empty }
3235
end
3336

@@ -46,6 +49,9 @@
4649
its(:current_operations) { is_expected.to include("Hold for workflow selection") }
4750
its(:percent_complete) { is_expected.to eq 0.43478260869565216 }
4851
its(:errors) { is_expected.to be_empty }
52+
its(:created_at) { is_expected.to eq '2015-04-20T17:58:43Z' }
53+
its(:updated_at) { is_expected.to eq '2015-04-21T18:38:50Z' }
54+
its(:finished_at) { is_expected.to be_nil }
4955
its(:tech_metadata) { is_expected.to be_empty }
5056
end
5157
context "a cancelled encode" do
@@ -61,6 +67,9 @@
6167
its(:current_operations) { is_expected.to include("Tagging dublin core catalogs for publishing") }
6268
its(:percent_complete) { is_expected.to eq 1.7391304347826086 }
6369
its(:errors) { is_expected.to be_empty }
70+
its(:created_at) { is_expected.to eq '2015-04-20T18:01:57Z' }
71+
its(:updated_at) { is_expected.to eq '2015-04-21T18:46:05Z' }
72+
its(:finished_at) { is_expected.to eq '2015-04-21T18:46:05Z' }
6473
its(:tech_metadata) { is_expected.to be_empty }
6574
end
6675
context "a completed encode" do
@@ -78,6 +87,9 @@
7887
its(:current_operations) { is_expected.to include("Cleaning up") }
7988
its(:percent_complete) { is_expected.to eq 100 }
8089
its(:errors) { is_expected.to be_empty }
90+
its(:created_at) { is_expected.to eq '2015-04-21T18:08:00Z' }
91+
its(:updated_at) { is_expected.to eq '2015-04-21T18:14:18Z' }
92+
its(:finished_at) { is_expected.to eq '2015-04-21T18:14:18Z' }
8193
its(:tech_metadata) { is_expected.to be_empty }
8294
end
8395
context "a failed encode" do
@@ -95,6 +107,9 @@
95107
its(:current_operations) { is_expected.to include("Cleaning up after failure") }
96108
its(:percent_complete) { is_expected.to eq 56.666666666666664 }
97109
its(:errors) { is_expected.to include failed_errors }
110+
its(:created_at) { is_expected.to eq '2015-04-09T16:12:00Z' }
111+
its(:updated_at) { is_expected.to eq '2015-04-09T16:14:06Z' }
112+
its(:finished_at) { is_expected.to eq '2015-04-09T16:14:06Z' }
98113
its(:tech_metadata) { is_expected.to include failed_tech_metadata }
99114
end
100115
end
@@ -166,6 +181,9 @@
166181
its(:current_operations) { is_expected.to include("Hold for workflow selection") }
167182
its(:percent_complete) { is_expected.to eq 0.43478260869565216 }
168183
its(:errors) { is_expected.to be_empty }
184+
its(:created_at) { is_expected.to eq '2015-04-20T17:58:43Z' }
185+
its(:updated_at) { is_expected.to eq '2015-04-21T18:38:50Z' }
186+
its(:finished_at) { is_expected.to be_nil }
169187
its(:tech_metadata) { is_expected.to be_empty }
170188
end
171189

spec/integration/zencoder_adapter_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
its(:current_operations) { is_expected.to be_empty }
3737
its(:percent_complete) { is_expected.to eq 0 }
3838
its(:errors) { is_expected.to be_empty }
39+
its(:created_at) { is_expected.to eq '2015-06-10T14:38:47Z' }
40+
its(:updated_at) { is_expected.to eq '2015-06-10T14:38:47Z' }
41+
its(:finished_at) { is_expected.to be_nil }
3942
its(:tech_metadata) { is_expected.to be_empty }
4043
end
4144

@@ -59,6 +62,9 @@
5962
its(:current_operations) { is_expected.to be_empty }
6063
its(:percent_complete) { is_expected.to eq 30.0 }
6164
its(:errors) { is_expected.to be_empty }
65+
its(:created_at) { is_expected.to eq '2015-06-09T16:18:26Z' }
66+
its(:updated_at) { is_expected.to eq '2015-06-09T16:18:28Z' }
67+
its(:finished_at) { is_expected.to be_nil }
6268
its(:tech_metadata) { is_expected.to eq running_tech_metadata }
6369
end
6470

@@ -73,6 +79,9 @@
7379
its(:current_operations) { is_expected.to be_empty }
7480
its(:percent_complete) { is_expected.to eq 0 }
7581
its(:errors) { is_expected.to be_empty }
82+
its(:created_at) { is_expected.to eq '2015-06-08T20:43:23Z' }
83+
its(:updated_at) { is_expected.to eq '2015-06-08T20:43:26Z' }
84+
its(:finished_at) { is_expected.to eq '2015-06-08T20:43:26Z' }
7685
its(:tech_metadata) { is_expected.to be_empty }
7786
end
7887

@@ -90,6 +99,9 @@
9099
its(:current_operations) { is_expected.to be_empty }
91100
its(:percent_complete) { is_expected.to eq 100 }
92101
its(:errors) { is_expected.to be_empty }
102+
its(:created_at) { is_expected.to eq '2015-06-08T18:13:53Z' }
103+
its(:updated_at) { is_expected.to eq '2015-06-08T18:14:06Z' }
104+
its(:finished_at) { is_expected.to eq '2015-06-08T18:14:06Z' }
93105
its(:tech_metadata) { is_expected.to eq completed_tech_metadata }
94106
end
95107

@@ -106,6 +118,9 @@
106118
its(:current_operations) { is_expected.to be_empty }
107119
its(:percent_complete) { is_expected.to eq 0 }
108120
its(:errors) { is_expected.to include failed_errors }
121+
its(:created_at) { is_expected.to eq '2015-06-09T20:52:57Z' }
122+
its(:updated_at) { is_expected.to eq '2015-06-09T20:53:00Z' }
123+
its(:finished_at) { is_expected.to eq '2015-06-09T20:53:00Z' }
109124
its(:tech_metadata) { is_expected.to be_empty }
110125
end
111126
end
@@ -147,6 +162,9 @@
147162
its(:current_operations) { is_expected.to be_empty }
148163
its(:percent_complete) { is_expected.to eq 30.0 }
149164
its(:errors) { is_expected.to be_empty }
165+
its(:created_at) { is_expected.to eq '2015-06-09T16:18:26Z' }
166+
its(:updated_at) { is_expected.to eq '2015-06-09T16:18:28Z' }
167+
its(:finished_at) { is_expected.to be_nil }
150168
its(:tech_metadata) { is_expected.to eq reload_tech_metadata }
151169
end
152170
end

0 commit comments

Comments
 (0)