Skip to content

Commit

Permalink
Add timestamp methods to encode
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcolvar committed Dec 2, 2015
1 parent 7c461a9 commit d95ce45
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
18 changes: 18 additions & 0 deletions lib/active_encode/engine_adapters/matterhorn_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def build_encode(workflow, cast)
encode.state = convert_state(workflow)
encode.current_operations = convert_current_operations(workflow)
encode.percent_complete = calculate_percent_complete(workflow)
encode.created_at = convert_created_at(workflow)
encode.updated_at = convert_updated_at(workflow)
encode.finished_at = convert_finished_at(workflow) unless encode.running?
encode.output = convert_output(workflow, encode.options)
encode.errors = convert_errors(workflow)
encode.tech_metadata = convert_tech_metadata(workflow)
Expand Down Expand Up @@ -141,6 +144,21 @@ def convert_errors(workflow)
workflow.xpath('//errors/error/text()').map(&:to_s)
end

def convert_created_at(workflow)
created_at = workflow.xpath('mediapackage/@start').last.to_s
created_at.present? ? Time.parse(created_at).iso8601 : nil
end

def convert_updated_at(workflow)
updated_at = workflow.xpath('//operation[@state!="INSTANTIATED"]/completed/text()').last.to_s
updated_at.present? ? Time.strptime(updated_at, "%Q").utc.iso8601 : nil
end

def convert_finished_at(workflow)
finished_at = workflow.xpath('//operation[@state!="INSTANTIATED"]/completed/text()').last.to_s
finished_at.present? ? Time.strptime(finished_at, "%Q").utc.iso8601 : nil
end

def convert_options(workflow)
options = {}
options[:preset] = workflow.xpath('template/text()').to_s
Expand Down
3 changes: 3 additions & 0 deletions lib/active_encode/engine_adapters/zencoder_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def build_encode(job_details, cast)
job_progress = get_job_progress(encode.id)
encode.current_operations = convert_current_operations(job_progress)
encode.percent_complete = convert_percent_complete(job_progress, job_details)
encode.created_at = job_details.body["job"]["created_at"]
encode.updated_at = job_details.body["job"]["updated_at"]
encode.finished_at = job_details.body["job"]["finished_at"]
encode.output = convert_output(job_details)
encode.errors = convert_errors(job_details)
encode.tech_metadata = convert_tech_metadata(job_details.body["job"]["input_media_file"])
Expand Down
7 changes: 4 additions & 3 deletions lib/active_encode/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ module Status
included do
# Current state of the encoding process
attr_accessor :state

attr_accessor :current_operations

attr_accessor :percent_complete

attr_accessor :errors

attr_accessor :created_at
attr_accessor :finished_at
attr_accessor :updated_at
end

def created?
Expand Down
18 changes: 18 additions & 0 deletions spec/integration/matterhorn_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
its(:current_operations) { is_expected.to be_empty }
its(:percent_complete) { is_expected.to eq 0 }
its(:errors) { is_expected.to be_empty }
its(:created_at) { is_expected.to eq '2015-04-24T15:44:47Z' }
its(:updated_at) { is_expected.to be_nil }
its(:finished_at) { is_expected.to be_nil }
its(:tech_metadata) { is_expected.to be_empty }
end

Expand All @@ -46,6 +49,9 @@
its(:current_operations) { is_expected.to include("Hold for workflow selection") }
its(:percent_complete) { is_expected.to eq 0.43478260869565216 }
its(:errors) { is_expected.to be_empty }
its(:created_at) { is_expected.to eq '2015-04-20T17:58:43Z' }
its(:updated_at) { is_expected.to eq '2015-04-21T18:38:50Z' }
its(:finished_at) { is_expected.to be_nil }
its(:tech_metadata) { is_expected.to be_empty }
end
context "a cancelled encode" do
Expand All @@ -61,6 +67,9 @@
its(:current_operations) { is_expected.to include("Tagging dublin core catalogs for publishing") }
its(:percent_complete) { is_expected.to eq 1.7391304347826086 }
its(:errors) { is_expected.to be_empty }
its(:created_at) { is_expected.to eq '2015-04-20T18:01:57Z' }
its(:updated_at) { is_expected.to eq '2015-04-21T18:46:05Z' }
its(:finished_at) { is_expected.to eq '2015-04-21T18:46:05Z' }
its(:tech_metadata) { is_expected.to be_empty }
end
context "a completed encode" do
Expand All @@ -78,6 +87,9 @@
its(:current_operations) { is_expected.to include("Cleaning up") }
its(:percent_complete) { is_expected.to eq 100 }
its(:errors) { is_expected.to be_empty }
its(:created_at) { is_expected.to eq '2015-04-21T18:08:00Z' }
its(:updated_at) { is_expected.to eq '2015-04-21T18:14:18Z' }
its(:finished_at) { is_expected.to eq '2015-04-21T18:14:18Z' }
its(:tech_metadata) { is_expected.to be_empty }
end
context "a failed encode" do
Expand All @@ -95,6 +107,9 @@
its(:current_operations) { is_expected.to include("Cleaning up after failure") }
its(:percent_complete) { is_expected.to eq 56.666666666666664 }
its(:errors) { is_expected.to include failed_errors }
its(:created_at) { is_expected.to eq '2015-04-09T16:12:00Z' }
its(:updated_at) { is_expected.to eq '2015-04-09T16:14:06Z' }
its(:finished_at) { is_expected.to eq '2015-04-09T16:14:06Z' }
its(:tech_metadata) { is_expected.to include failed_tech_metadata }
end
end
Expand Down Expand Up @@ -166,6 +181,9 @@
its(:current_operations) { is_expected.to include("Hold for workflow selection") }
its(:percent_complete) { is_expected.to eq 0.43478260869565216 }
its(:errors) { is_expected.to be_empty }
its(:created_at) { is_expected.to eq '2015-04-20T17:58:43Z' }
its(:updated_at) { is_expected.to eq '2015-04-21T18:38:50Z' }
its(:finished_at) { is_expected.to be_nil }
its(:tech_metadata) { is_expected.to be_empty }
end

Expand Down
18 changes: 18 additions & 0 deletions spec/integration/zencoder_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
its(:current_operations) { is_expected.to be_empty }
its(:percent_complete) { is_expected.to eq 0 }
its(:errors) { is_expected.to be_empty }
its(:created_at) { is_expected.to eq '2015-06-10T14:38:47Z' }
its(:updated_at) { is_expected.to eq '2015-06-10T14:38:47Z' }
its(:finished_at) { is_expected.to be_nil }
its(:tech_metadata) { is_expected.to be_empty }
end

Expand All @@ -59,6 +62,9 @@
its(:current_operations) { is_expected.to be_empty }
its(:percent_complete) { is_expected.to eq 30.0 }
its(:errors) { is_expected.to be_empty }
its(:created_at) { is_expected.to eq '2015-06-09T16:18:26Z' }
its(:updated_at) { is_expected.to eq '2015-06-09T16:18:28Z' }
its(:finished_at) { is_expected.to be_nil }
its(:tech_metadata) { is_expected.to eq running_tech_metadata }
end

Expand All @@ -73,6 +79,9 @@
its(:current_operations) { is_expected.to be_empty }
its(:percent_complete) { is_expected.to eq 0 }
its(:errors) { is_expected.to be_empty }
its(:created_at) { is_expected.to eq '2015-06-08T20:43:23Z' }
its(:updated_at) { is_expected.to eq '2015-06-08T20:43:26Z' }
its(:finished_at) { is_expected.to eq '2015-06-08T20:43:26Z' }
its(:tech_metadata) { is_expected.to be_empty }
end

Expand All @@ -90,6 +99,9 @@
its(:current_operations) { is_expected.to be_empty }
its(:percent_complete) { is_expected.to eq 100 }
its(:errors) { is_expected.to be_empty }
its(:created_at) { is_expected.to eq '2015-06-08T18:13:53Z' }
its(:updated_at) { is_expected.to eq '2015-06-08T18:14:06Z' }
its(:finished_at) { is_expected.to eq '2015-06-08T18:14:06Z' }
its(:tech_metadata) { is_expected.to eq completed_tech_metadata }
end

Expand All @@ -106,6 +118,9 @@
its(:current_operations) { is_expected.to be_empty }
its(:percent_complete) { is_expected.to eq 0 }
its(:errors) { is_expected.to include failed_errors }
its(:created_at) { is_expected.to eq '2015-06-09T20:52:57Z' }
its(:updated_at) { is_expected.to eq '2015-06-09T20:53:00Z' }
its(:finished_at) { is_expected.to eq '2015-06-09T20:53:00Z' }
its(:tech_metadata) { is_expected.to be_empty }
end
end
Expand Down Expand Up @@ -147,6 +162,9 @@
its(:current_operations) { is_expected.to be_empty }
its(:percent_complete) { is_expected.to eq 30.0 }
its(:errors) { is_expected.to be_empty }
its(:created_at) { is_expected.to eq '2015-06-09T16:18:26Z' }
its(:updated_at) { is_expected.to eq '2015-06-09T16:18:28Z' }
its(:finished_at) { is_expected.to be_nil }
its(:tech_metadata) { is_expected.to eq reload_tech_metadata }
end
end

0 comments on commit d95ce45

Please sign in to comment.