Skip to content

Commit

Permalink
AWS上の配信用リソースを管理するためのstreamingsテーブルとStreamingモデルを追加する
Browse files Browse the repository at this point in the history
  • Loading branch information
takaishi committed Sep 6, 2023
1 parent 66c1a85 commit e76879b
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 1 deletion.
41 changes: 41 additions & 0 deletions app/controllers/admin/streamings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Admin::StreamingsController < ApplicationController
include SecuredAdmin


def index
@tracks = @conference.tracks
end

def create
@streaming = Streaming.new(streaming_params.merge(conference_id: @conference.id))

respond_to do |format|
if @streaming.save && create_aws_resources
format.html { redirect_to(admin_streamings_path, notice: 'Streaming AWS Resources is creating...') }
format.json { render(:show, status: :ok, location: @job) }
else
format.html { redirect_to(admin_streaming_path, flash: { error: @job.errors.messages }) }
format.json { render(json: @job.errors, status: :unprocessable_entity) }
end
end
end

def create_aws_resources
@streaming ||= Streaming.find(params[:id])
CreateStreamingAwsResourcesJob.perform_later(@streaming)
end

def delete_aws_resources
@streaming ||= Streaming.find(params[:id])
DeleteStreamingAwsResourcesJob.perform_later(@streaming)
@streaming.update!(status: 'deleting')
respond_to do |format|
format.html { redirect_to(admin_streamings_path, notice: 'Streaming AWS Resources is deleting...') }
format.json { head(:no_content) }
end
end

def streaming_params
params.require(:streaming).permit(:id, :conference_id, :track_id, :status)
end
end
8 changes: 8 additions & 0 deletions app/controllers/api/v1/streamings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Api::V1::StreamingsController < ApplicationController
include SecuredPublicApi

def index
@conference ||= Conference.find_by(abbr: params[:eventAbbr])
@streamings = @conference.streamings
end
end
18 changes: 18 additions & 0 deletions app/jobs/create_streaming_aws_resources_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class CreateStreamingAwsResourcesJob < ApplicationJob
include EnvHelper
include LogoutHelper

# queue_as :default
self.queue_adapter = :async

def perform(*args)
# Rails.logger.level = Logger::DEBUG
logger.info('Perform CreateMediaPackageV2Job')

@streaming.update!(status: 'created')
rescue => e
@streaming.update!(status: 'error')
logger.error(e.message)
logger.error(e.backtrace.join("\n"))
end
end
18 changes: 18 additions & 0 deletions app/jobs/delete_streaming_aws_resources_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class DeleteStreamingAwsResourcesJob < ApplicationJob
include EnvHelper
include MediaPackageV2Helper
include LogoutHelper

# queue_as :default
self.queue_adapter = :async

def perform(*args)
# Rails.logger.level = Logger::DEBUG
logger.info('Perform DeleteStreamingAwsResourcesJob')

@streaming.update!(status: 'deleted')
rescue => e
logger.error(e.message)
logger.error(e.backtrace.join("\n"))
end
end
1 change: 1 addition & 0 deletions app/models/conference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Conference < ApplicationRecord
has_many :talk_times
has_many :talk_categories
has_many :talk_difficulties
has_many :streamings
has_many :speakers
has_many :announcements
has_many :speaker_announcements
Expand Down
35 changes: 35 additions & 0 deletions app/models/streaming.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# == Schema Information
#
# Table name: streamings
#
# id :string(255) not null, primary key
# status :string(255) not null
# created_at :datetime not null
# updated_at :datetime not null
# conference_id :bigint not null
# track_id :bigint not null
#
# Indexes
#
# index_streamings_on_conference_id (conference_id)
# index_streamings_on_conference_id_and_track_id (conference_id,track_id) UNIQUE
# index_streamings_on_track_id (track_id)
#
# Foreign Keys
#
# fk_rails_... (conference_id => conferences.id)
# fk_rails_... (track_id => tracks.id)
#

class Streaming < ApplicationRecord
before_create :set_uuid

belongs_to :conference
belongs_to :track

STATUS_CREATING = 'creating'.freeze
STATUS_CRTEATED = 'created'.freeze
STATUS_DELETING = 'deleting'.freeze
STATUS_DELETED = 'deleted'.freeze

end
2 changes: 2 additions & 0 deletions app/models/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Track < ApplicationRecord
has_one :live_stream_ivs
has_one :live_stream_media_live
has_one :media_package_channel
has_one :streaming

belongs_to :room, optional: true

def on_air_talk
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/_navigator.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<%= render 'admin/nav_item', name: 'TimeTable', path: admin_timetables_path, active: controller_name == 'timetables' %>
<%= render 'admin/nav_item', name: 'Tracks', path: admin_tracks_path, active: controller_name == 'tracks'%>
<%= render 'admin/nav_item', name: 'IVS', path: admin_live_stream_ivs_path, active: action_name == 'live_stream_ivs' %>
<%= render 'admin/nav_item', name: 'Streaming AWS Resources', path: admin_streamings_path, active: action_name == 'streaming' %>
<%= render 'admin/nav_item', name: 'HarvestJobs', path: admin_harvest_jobs_path, active: action_name == 'media_package_harvest_job' %>
<%= render 'admin/nav_item', name: 'Statistics', path: admin_statistics_path, active: action_name == 'statistics' %>
<%= render 'admin/nav_item', name: 'Sponsors', path: admin_sponsors_path, active: controller_name == 'sponsors' || action_name == 'show_sponsor' %>
Expand Down
7 changes: 7 additions & 0 deletions app/views/admin/streamings/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%= render 'admin/layout' do %>
<div class="row mb-2">
<div class="col-10 d-flex align-items-center">
<h2>配信用AWSリソース管理</h2>
</div>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/api/v1/streamings/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
json.array!(@streamings) do |streaming|
json.id(streaming.id)
json.status(streaming.status)
json.destination_url(streaming.destination_url)
json.playback_url(streaming.playback_url)
end
9 changes: 9 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
resources :proposals, only: [:index]
resources :speakers, only: [:index]
resources :tracks, only: [:index, :show]
resources :streamings, only: [:index]
resources :sponsors, only: [:index]
resources :speakers, only: [:index, :show]
resources :chat_messages, only: [:index, :create, :update]
Expand Down Expand Up @@ -61,6 +62,12 @@
resource :timetable, only: [:update]
resources :announcements
resources :speaker_announcements
resources :streamings
post 'create_aws_resources' => 'streamings#create_aws_resources'
post 'delete_aws_resources' => 'streamings#delete_aws_resources'
post 'start_media_live_channel' => 'media_live_channel#start_channel'
post 'stop_media_live_channel' => 'media_live_channel#stop_channel'

post 'publish_timetable' => 'timetables#publish'
post 'close_timetable' => 'timetables#close'
get 'preview_timetable' => 'timetables#preview'
Expand All @@ -84,6 +91,8 @@
post 'bulk_delete_media_live' => 'live_stream_media_live#bulk_delete'
post 'bulk_create_media_package' => 'live_stream_media_package#bulk_create'
post 'bulk_delete_media_package' => 'live_stream_media_package#bulk_delete'
post 'bulk_create_media_package_v2' => 'live_stream_media_package_v2#bulk_create'
post 'bulk_delete_media_package_v2' => 'live_stream_media_package_v2#bulk_delete'
resources :harvest_jobs
end

Expand Down
16 changes: 16 additions & 0 deletions db/migrate/20230627103419_create_streamings_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreateStreamingsTable < ActiveRecord::Migration[7.0]
def up
create_table :streamings, id: :string do |t|
t.belongs_to :conference, null: false, foreign_key: true, type: :bigint
t.belongs_to :track, null: false, foreign_key: true, type: :bigint
t.string :status, null: false

t.timestamps
t.index [:conference_id, :track_id], unique: true
end unless ActiveRecord::Base.connection.table_exists?(:streamings)
end

def down
drop_table :streamings
end
end
15 changes: 14 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_06_18_045613) do
ActiveRecord::Schema[7.0].define(version: 2023_06_27_103419) do
create_table "access_logs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name"
t.string "sub"
Expand Down Expand Up @@ -410,6 +410,17 @@
t.index ["conference_id"], name: "index_stats_of_registrants_on_conference_id"
end

create_table "streamings", id: :string, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "conference_id", null: false
t.bigint "track_id", null: false
t.string "status", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["conference_id", "track_id"], name: "index_streamings_on_conference_id_and_track_id", unique: true
t.index ["conference_id"], name: "index_streamings_on_conference_id"
t.index ["track_id"], name: "index_streamings_on_track_id"
end

create_table "talk_categories", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
Expand Down Expand Up @@ -563,6 +574,8 @@
add_foreign_key "sponsor_profiles", "conferences"
add_foreign_key "sponsor_types", "conferences"
add_foreign_key "sponsors", "conferences"
add_foreign_key "streamings", "conferences"
add_foreign_key "streamings", "tracks"
add_foreign_key "talk_times", "conferences"
add_foreign_key "tickets", "conferences"
add_foreign_key "video_registrations", "talks"
Expand Down

0 comments on commit e76879b

Please sign in to comment.