forked from WowzaMediaSystems/wsc-sdk-ruby
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstats.rb
43 lines (32 loc) · 1.52 KB
/
stats.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
####> This code and all components © 2015 – 2019 Wowza Media Systems, LLC. All rights reserved.
####> This code is licensed pursuant to the BSD 3-Clause License.
require "wsc_sdk"
require_relative "../client" # Get our client
require_relative "../helpers" # Include some helpers to make the code more direct
# Ensure the args passed in are present
arguments = ask_for_arguments(__FILE__, transcoder_id: nil)
# Extract some data into convenience variables
transcoders = $client.transcoders
transcoder_id = arguments[0]
# Request the transcoder object
transcoder = transcoders.find(transcoder_id)
# Handle an API error (in the helpers.rb file)
handle_api_error(transcoder, "There was an error finding the transcoder") unless transcoder.success?
# Request the transcoder state
state = transcoder.state
# Handle an API error (in the helpers.rb file)
handle_api_error(state, "There was an error getting the transcoder state") unless state.success?
# Ensure the transcoder is started
if state.state != 'started'
# Start the transcoder and wait
result = transcoder.start do |wait_state, transcoder_state|
puts "Waiting for transcoder to start"
end
end
# Request the current statistics from the transcoder
stats = transcoder.stats
# Handle an API error (in the helpers.rb file)
handle_api_error(stats, "There was an error getting the transcoder stats") unless stats.success?
# Output the current transcoder statistics
# Defined in helpers.rb
output_model_attributes(stats, "Transcoder Stats:")