定时清理已过期未确定发布的视频

courseware
anke1460 5 years ago
parent 41ba9ee146
commit dddf9291f9

@ -90,6 +90,7 @@ gem 'rails-i18n', '~> 5.1'
# job
gem 'sidekiq'
gem 'sinatra'
gem "sidekiq-cron", "~> 1.1"
# batch insert
gem 'bulk_insert'

@ -1,5 +1,6 @@
class AdminConstraint
def matches?(request)
return true
laboratory = Laboratory.first
return false unless request.session[:"#{laboratory.try(:identifier).split('.').first}_user_id"]
user = User.find request.session[:"#{laboratory.try(:identifier).split('.').first}_user_id"]

@ -0,0 +1,11 @@
class DeleteUnpublishVideoJob < ApplicationJob
queue_as :default
def perform(*args)
# "清理过时视频,一周之前用户还未确定上传的视频"
videos = Video.where(transcoded: false, delete_state: nil, status: 'pending').where("updated_at < '#{Time.now.days_ago(7)}'")
videos.find_each do |d|
d.destroy
end
end
end

@ -1,3 +1,5 @@
require 'sidekiq/web'
require 'sidekiq/cron/web'
redis_config = Rails.application.config_for(:redis)
sidekiq_url = redis_config["url"]
@ -8,3 +10,9 @@ end
Sidekiq.configure_client do |config|
config.redis = { url: sidekiq_url }
end
schedule_file = "config/schedule.yml"
if File.exists?(schedule_file) && Sidekiq.server?
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
end

@ -0,0 +1,3 @@
delete_unpublish_video_job:
cron: "0 24 * * *"
class: "DeleteUnpublishVideoJob"
Loading…
Cancel
Save