Initial commit

This commit is contained in:
Senad Uka
2020-05-31 22:38:19 +02:00
commit 858fafc3c5
1280 changed files with 65918 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
class AddHeadshotCollectionUidToProjectJob < ApplicationJob
queue_as :default
def perform(project)
# TODO: move this into Project model?
collection = HeadshotCollection.for_project(project)
response = BrayniacAI::Collection.create!(collection)
project.update_attribute(:headshot_collection_uid, response.collection_id)
end
end

View File

@@ -0,0 +1,17 @@
class AnalyzeAudioJob < ApplicationJob
queue_as :default
def perform(video)
response = BrayniacAI::AudioRecognition.create! AudioAnalysis.new(video)
video.update!({
audio_analysis_uid: response.job_id,
audio_analysis_started_at: Time.zone.now,
audio_analysis_status: :pending,
})
rescue StandardError => e
video.audio_analysis_failure!
Rails.logger.error("Failed to perform audio analysis for video(##{video.id})\n" + e.message)
end
end

View File

@@ -0,0 +1,27 @@
class AnalyzeVideoJob < ApplicationJob
queue_as :default
before_perform do |job|
video = job.arguments.first
ProjectsChannel.broadcast_video_analysis_update(video)
end
def perform(video, reanalysis: false)
response = BrayniacAI::FacialRecognition.create! VideoAnalysis.new(video, reanalysis)
video.update!({
analysis_uid: response.job_id,
analysis_started_at: Time.zone.now,
analysis_status: :pending,
})
rescue StandardError => e
video.analysis_failure!
Rails.logger.error("Failed to analyze video(##{video.id})\n" + e.message)
end
after_perform do |job|
video = job.arguments.first
ProjectsChannel.broadcast_video_analysis_update(video)
end
end

View File

@@ -0,0 +1,2 @@
class ApplicationJob < ActiveJob::Base
end

View File

@@ -0,0 +1,13 @@
class AttachContractToReleasableJob < ApplicationJob
queue_as :default
def perform(releasable)
contract = Contract.new(releasable)
releasable.contract.attach({
io: contract.to_pdf,
filename: contract.filename,
content_type: "application/pdf"
})
end
end

View File

@@ -0,0 +1,26 @@
require 'zoom_gateway'
class AttachRecordingToZoomMeetingJob < ApplicationJob
queue_as :default
def perform(zoom_meeting, recording_hash, download_token)
download_url = "#{recording_hash['download_url']}?access_token=#{download_token}"
file = URI.open(download_url)
if zoom_meeting.recording.attach(io: file, filename: file_name(zoom_meeting, recording_hash), content_type: 'video/mp4')
# Temorarily disabling notifications
# if zoom_meeting.project.present?
# ProjectsChannel.conference_recording_ready(zoom_meeting.project, zoom_meeting.recording)
# end
gateway = ZoomGateway.new
gateway.delete_recording(zoom_meeting.api_meeting_id, recording_hash['id'])
end
end
private
def file_name(zoom_meeting, recording_hash)
start = recording_hash['recording_start'].to_datetime
prefix = zoom_meeting.project.present? ? "#{zoom_meeting.project.name}_" : ''
"#{prefix}video_conference_date#{start.strftime("%Y-%m-%d")}_Time_#{start.strftime("%T")}.mp4"
end
end

View File

@@ -0,0 +1,49 @@
class GenerateContractsZipJob < ApplicationJob
queue_as :default
include Rails.application.routes.url_helpers
include ActionView::Helpers::UrlHelper
before_perform do |job|
@project = job.arguments.first
@download = job.arguments.second
release_type = job.arguments.third
@folder_name = "#{@project.name.parameterize}_#{get_release_name(release_type).gsub('_', '-')}"
@download.update!(name: @folder_name, status: :pending)
end
def perform(project, download, release_type, release_ids)
releases = project.public_send(get_release_name(release_type)).where(id: release_ids)
::ReleaseContractCollectionService.new(releases, @folder_name).build do |dir, files|
zipfile_name = "#{dir}/#{@folder_name}.zip"
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
files.each do |attachment|
zipfile.add(attachment, File.join("#{dir}/", attachment))
end
end
@download.file.attach(io: File.open(zipfile_name), filename: @folder_name)
end
rescue StandardError => e
Rails.logger.error("Failed to generate download for project (##{project.id}) with release type #{release_type}\n" + e.message)
@download.failure!
ProjectsChannel.broadcast_download_generation_update(@download, I18n.t("contract_downloads.download.failure"))
end
after_perform do |job|
if @download.pending? && @download.file.attached?
@download.success!
downloads_folder_link = link_to("Files > Downloads", project_downloads_path(I18n.locale, @project))
download_button = link_to("Download", rails_blob_path(@download.file, disposition: "attachment", only_path: true), class: "btn btn-success", target: :_blank)
ProjectsChannel.broadcast_download_generation_update(@download, I18n.t("contract_downloads.download.success", downloads_folder_link: downloads_folder_link, download_button: download_button, release_type: job.arguments.third.titleize))
end
end
private
def get_release_name(release_type)
release_type.constantize.model_name.plural
end
end

View File

@@ -0,0 +1,42 @@
class GenerateReportsZipJob < ApplicationJob
queue_as :default
include Rails.application.routes.url_helpers
include ActionView::Helpers::UrlHelper
before_perform do |job|
@project = job.arguments.first
@download = job.arguments.second
@download.update!(status: :pending)
end
def perform(project, download, folder_name)
videos = project.videos.reports_published
::ReportCollectionService.new(videos).build do |dir, files|
zipfile_name = "#{dir}/#{folder_name}.zip"
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
files.each do |attachment|
zipfile.add(attachment, File.join("#{dir}/", attachment))
end
end
@download.file.attach(io: File.open(zipfile_name), filename: folder_name)
end
rescue StandardError => e
Rails.logger.error("Failed to generate download for project (##{project.id})\n" + e.message)
@download.failure!
ProjectsChannel.broadcast_download_generation_update(@download, I18n.t("report_downloads.download.failure"))
end
after_perform do |job|
if @download.pending? && @download.file.attached?
@download.success!
downloads_folder_link = link_to("Files > Downloads", project_downloads_path(I18n.locale, @project))
download_button = link_to("Download", rails_blob_path(@download.file, disposition: "attachment", only_path: true), class: "btn btn-success", target: :_blank)
ProjectsChannel.broadcast_download_generation_update(@download, I18n.t("report_downloads.download.success", downloads_folder_link: downloads_folder_link, download_button: download_button))
end
end
end

View File

@@ -0,0 +1,28 @@
class SetTagsForReleasableJob < ApplicationJob
queue_as :default
before_perform do |job|
releasable = job.arguments.first
releasable.tagging_started!
end
def perform(releasable)
tags = releasable.photos.flat_map do |photo|
BrayniacAI::Tag.create(bucket_name: bucket_name, object_name: photo.key).to_a
end
releasable.update! \
internal_tag_list: tags,
tagging_status: :finished
rescue StandardError => e
releasable.tagging_failed!
Rails.logger.error("Failed to attach tags to AppearanceRelease(##{releasable.id})\n" + e.message)
end
private
def bucket_name
ENV['AWS_BUCKET']
end
end

View File

@@ -0,0 +1,18 @@
class SubmitHubspotFormJob < ApplicationJob
queue_as :default
def perform(email, company_name, additional_params = {})
hubspot_form_guid = ENV["HUBSPOT_FORM_GUID"]
return unless hubspot_form_guid.present?
submission_params = {
email: email,
company: company_name
}.merge(additional_params)
form = Hubspot::Form.new("guid" => hubspot_form_guid)
is_form_sumitted = form.submit(submission_params)
raise StandardError.new "Failed to submit the hubspot form data: #{is_form_sumitted}" unless is_form_sumitted
end
end

View File

@@ -0,0 +1,8 @@
class TrackAnalyticsJob < ApplicationJob
queue_as :default
def perform(user, account, event_name, *args)
analytics = Analytics.new(user, account)
analytics.public_send(event_name, *args)
end
end