class AnalysisNotification def self.build(type, job_id) case type.to_s when "audio" AudioAnalysisNotification.new(job_id) when "video" VideoAnalysisNotification.new(job_id) end end class VideoAnalysisNotification attr_reader :job_id def initialize(job_id) @job_id = job_id end def video # TODO: add index for analysis_uid @video ||= Video.find_by!(analysis_uid: job_id) end def success! video.analysis_success! ProjectsChannel.broadcast_video_analysis_update(video) end def failure! video.analysis_failure! ProjectsChannel.broadcast_video_analysis_update(video) end end class AudioAnalysisNotification attr_reader :job_id def initialize(job_id) @job_id = job_id end def video # TODO: add index for audio_analysis_uid @video ||= Video.find_by!(audio_analysis_uid: job_id) end def success! video.audio_analysis_success! ProjectsChannel.broadcast_video_analysis_update(video) end def failure! video.audio_analysis_failure! ProjectsChannel.broadcast_video_analysis_update(video) end end end