Class: Conversant::V3::Services::LMS::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/conversant/v3/services/lms/job.rb

Overview

Job management service for live streaming operations

Provides comprehensive job management functionality for live streaming including:

  • Job listing and filtering
  • Job status tracking
  • Stream profile information
  • Manifest URL generation

Examples:

Query streaming jobs

lms = Conversant::V3.lms(12345)

# Get all streaming jobs
jobs = lms.job.where(status: 'streaming')

jobs.each do |job|
  puts "Job #{job[:id]}: #{job[:name]} - #{job[:status]}"
  puts "  Manifest: #{job[:manifest]}"
  puts "  Profiles: #{job[:profiles].length}"
end

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Job

Initialize job service

Parameters:

  • parent (LMS)

    the parent LMS service instance

Since:

  • 1.0.0



35
36
37
# File 'lib/conversant/v3/services/lms/job.rb', line 35

def initialize(parent)
  @parent = parent
end

Instance Attribute Details

#parentLMS (readonly)

Returns the parent LMS service instance.

Returns:

  • (LMS)

    the parent LMS service instance

Since:

  • 1.0.0



30
31
32
# File 'lib/conversant/v3/services/lms/job.rb', line 30

def parent
  @parent
end

Instance Method Details

#where(**params) ⇒ Array<Hash>?

Query streaming jobs with filters

Retrieves a list of streaming jobs matching the specified filters. Returns detailed information about each job including status, profiles, and manifest URLs.

Examples:

Get streaming jobs

jobs = lms.job.where(status: 'streaming', limit: 50)
jobs.each do |job|
  puts "#{job[:name]} (#{job[:status]}) - #{job[:manifest]}"
end

Get all jobs

all_jobs = lms.job.where

Parameters:

  • params (Hash)

    query parameters

Options Hash (**params):

  • :status (String)

    job status filter ('streaming', 'ready', 'interrupted')

  • :limit (Integer)

    maximum number of results

  • :offset (Integer)

    pagination offset

Returns:

  • (Array<Hash>, nil)

    array of job hashes with details, or nil on error Each hash contains:

    • :entity [Integer] OSP entity ID
    • :id [Integer] job ID
    • :app [String] application name
    • :name [String] stream name
    • :status [String] job status ('ready', 'streaming', 'interrupted')
    • :created_at [DateTime] job creation timestamp
    • :started_at [DateTime] job start timestamp
    • :ended_at [DateTime] job end timestamp
    • :client [String] client IP address
    • :encoder [String] encoder IP address
    • :server [String] execution server
    • :manifest [String] manifest URL
    • :profiles [Array] array of stream profiles
    • :transcoding [Boolean] transcoding enabled
    • :gpu [Boolean] GPU acceleration enabled

Since:

  • 1.0.0



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/conversant/v3/services/lms/job.rb', line 78

def where(**params)
  response = JSON.parse(@parent.send(:call, 'GET', "/v4/streams?#{params.to_query}"))
  return nil unless response

  items = response['list'] || response[:list] || []

  items.map do |item|
    status = item['status']&.to_i || item[:status]&.to_i
    inbound = item['stream_rtmp_inbound'] || item[:stream_rtmp_inbound]

    profiles = (item['stream_rtmp_outbounds'] || item[:stream_rtmp_outbounds])&.map do |stream|
      {
        preset: stream['preset_name'] || stream[:preset_name],
        type: stream['type'] || stream[:type],
        profile: build_profile_url(inbound, item, stream)
      }
    end

    {
      entity: item['osp_id'] || item[:osp_id],
      id: item['id'] || item[:id],
      app: item['app'] || item[:app],
      name: item['stream'] || item[:stream],
      status: parse_status(status),
      created_at: parse_timestamp(item['created'] || item[:created]),
      started_at: parse_timestamp(item['started'] || item[:started]),
      ended_at: parse_timestamp(item['ended'] || item[:ended]),
      client: inbound && (inbound['client_ip'] || inbound[:client_ip]),
      encoder: extract_encoder(item),
      server: item['exec_ta'] || item[:exec_ta],
      manifest: build_manifest_url(inbound, item, profiles),
      profiles: profiles || [],
      transcoding: item['transcoding'] || item[:transcoding],
      gpu: (item['gpu'] || item[:gpu]) == 'gpu'
    }
  end
rescue StandardError => e
  @parent.send(:logger).error "LMS::Job.where error: #{e.message}"
  nil
end