[Git][noosfero/noosfero][stable-1.10] Adds multitenancy support to video_processor

Rodrigo Souto gitlab at mg.gitlab.com
Tue Oct 31 18:41:13 BRST 2017


Rodrigo Souto pushed to branch stable-1.10 at Noosfero / noosfero


Commits:
ad648f2a by Gabriel Silva at 2017-10-31T17:40:36-03:00
Adds multitenancy support to video_processor

Signed-off-by: Gabriel Silva <gabriel93.silva at gmail.com>

- - - - -


5 changed files:

- plugins/html5_video/lib/video_processor/logger.rb
- plugins/html5_video/lib/video_processor/recorder.rb
- plugins/html5_video/script/video_processor
- plugins/html5_video/script/video_processor_foreground.rb
- script/production


Changes:

=====================================
plugins/html5_video/lib/video_processor/logger.rb
=====================================
--- a/plugins/html5_video/lib/video_processor/logger.rb
+++ b/plugins/html5_video/lib/video_processor/logger.rb
@@ -9,6 +9,8 @@ module VideoProcessor
 
     def initialize(root_path)
       @root_path = root_path
+      create_logs_dir!
+
       @out_log = ::Logger.new info_log_path
       @err_log = ::Logger.new error_log_path
     end
@@ -22,11 +24,21 @@ module VideoProcessor
     end
 
     def info_log_path
-      File.join(@root_path, INFO_LOG)
+      File.join(env_dir, INFO_LOG)
     end
 
     def error_log_path
-      File.join(@root_path, ERR_LOG)
+      File.join(env_dir, ERR_LOG)
+    end
+
+    private
+
+    def env_dir
+      File.join(@root_path, ENV['RAILS_ENV'] || 'development')
+    end
+
+    def create_logs_dir!
+      FileUtils.mkdir_p(env_dir) unless File.directory?(env_dir)
     end
 
   end


=====================================
plugins/html5_video/lib/video_processor/recorder.rb
=====================================
--- a/plugins/html5_video/lib/video_processor/recorder.rb
+++ b/plugins/html5_video/lib/video_processor/recorder.rb
@@ -11,7 +11,8 @@ module VideoProcessor
 
       info = video_info.clone
       info.delete :output
-      `DISABLE_SPRING=1 rails runner -e #{RAILS_ENV} "env = Environment.find(#{env_id}); \
+      `DISABLE_SPRING=1 rails runner -e #{RAILS_ENV} "\
+       env = Environment.find(#{env_id}); \
        file = env.articles.find(#{video_id}); \
        video = FilePresenter.for(file); \
        video.web_versions = #{videos.to_s.gsub('"', "'")}; \
@@ -40,7 +41,8 @@ module VideoProcessor
         end
       end
 
-      `DISABLE_SPRING=1 rails runner -e #{RAILS_ENV} "env = Environment.find(#{env_id}); \
+      `DISABLE_SPRING=1 rails runner -e #{RAILS_ENV} "\
+       env = Environment.find(#{env_id}); \
        file = env.articles.find(#{video_id}); \
        video = FilePresenter.for(file); \
        video.web_versions = #{videos.to_s.gsub('"', "'")}; \
@@ -55,7 +57,8 @@ module VideoProcessor
         videos[format][size][:error] = error
       end
 
-      `DISABLE_SPRING=1 rails runner -e #{RAILS_ENV} "env = Environment.find(#{env_id}); \
+      `DISABLE_SPRING=1 rails runner -e #{RAILS_ENV} "\
+       env = Environment.find(#{env_id}); \
        file = env.articles.find(#{video_id}); \
        video = FilePresenter.for(file); \
        video.web_versions = #{videos.to_s.gsub('"', "'")}; \


=====================================
plugins/html5_video/script/video_processor
=====================================
--- a/plugins/html5_video/script/video_processor
+++ b/plugins/html5_video/script/video_processor
@@ -3,6 +3,8 @@
 require 'daemons'
 
 script = File.join(__dir__, 'video_processor_foreground.rb')
+env = ENV['RAILS_ENV'] || 'development'
 tmp_folder = File.join(__dir__, '../../../tmp/')
-Daemons.run(script, app_name: 'video_processor', dir_mode: :normal,
+Daemons.run(script, app_name: "video_processor.#{env}",
+                    dir_mode: :normal,
                     dir: tmp_folder)


=====================================
plugins/html5_video/script/video_processor_foreground.rb
=====================================
--- a/plugins/html5_video/script/video_processor_foreground.rb
+++ b/plugins/html5_video/script/video_processor_foreground.rb
@@ -9,7 +9,7 @@ require_relative '../lib/video_processor/logger'
 
 include VideoProcessor::Recorder
 
-RAILS_ENV = ENV['RAILS_ENV'] ? ENV['RAILS_ENV'] : 'development'
+RAILS_ENV = ENV['RAILS_ENV'] || 'development'
 NOOSFERO_ROOT = File.join(__dir__, '../../../')
 POOL = VideoProcessor::PoolManager.new(NOOSFERO_ROOT)
 
@@ -50,17 +50,15 @@ def process_all_files(env_id, pool=:waiting)
     # Moves the file to the ONGOING pool, so we can try again if the process
     # dies during the conversion. It removes the file from the pool if it was
     # processed, or adds it back to the WAITING pool if something went wrong.
-    Process.fork do
-      video_id = file.split('/').last
-      video_path = POOL.assign(env_id, video_id, pool)
-      begin
-        process_video(env_id, video_path, video_id)
-        POOL.pop(env_id, video_id)
-      rescue => e
-        LOGGER.error "Error while processing [Video #{video_id}]: #{e}"
-        POOL.pop(env_id, video_id)
-        POOL.push(env_id, video_id, video_path)
-      end
+    video_id = file.split('/').last
+    video_path = POOL.assign(env_id, video_id, pool)
+    begin
+      process_video(env_id, video_path, video_id)
+      POOL.pop(env_id, video_id)
+    rescue => e
+      LOGGER.error "Error while processing [Video #{video_id}]: #{e}"
+      POOL.pop(env_id, video_id)
+      POOL.push(env_id, video_id, video_path)
     end
   end
 end


=====================================
script/production
=====================================
--- a/script/production
+++ b/script/production
@@ -95,8 +95,8 @@ environments_loop() {
       RAILS_ENV=$env bundle exec ./script/delayed_job -i $env "$action"
       RAILS_ENV=$env bundle exec ./script/feed-updater "$action" -i $env
       ./script/whenever $action $env
+      RAILS_ENV=$env ./script/noosfero-plugins services "$action"
     done
-    RAILS_ENV=$env ./script/noosfero-plugins services "$action"
   else
     bundle exec ./script/delayed_job "$action"
     bundle exec ./script/feed-updater "$action"



View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/ad648f2a39a53f9055d4cf4285343670e3df8569

---
View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/ad648f2a39a53f9055d4cf4285343670e3df8569
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20171031/f5734527/attachment-0001.html>


More information about the Noosfero-dev mailing list