-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AWS上の配信用リソースを管理するためのstreamingsテーブルとStreamingモデルを追加する
- Loading branch information
Showing
13 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters