Change rap-starter to run persistently and watch for file changes

Instead of being executed every 30s by systemd, it's now a service that's
running all the time and will wait for .done files to start the processing
of recordings.
This commit is contained in:
Leonardo Crauss Daronco 2019-12-05 11:41:13 -03:00
parent d769849ad6
commit 53c3ed0d7d
3 changed files with 36 additions and 31 deletions

View File

@ -14,7 +14,7 @@
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
#
# You should have received a copy of the GNU Lesser General Public License
# along with BigBlueButton. If not, see <http://www.gnu.org/licenses/>.
@ -24,36 +24,29 @@ require 'rubygems'
require 'yaml'
require 'fileutils'
require 'resque'
require 'rb-inotify'
def archive_recorded_meetings(props)
recording_dir = props['recording_dir']
recorded_done_files = Dir.glob("#{recording_dir}/status/recorded/*.done")
def archive_recorded_meetings(done_file)
FileUtils.mkdir_p("#{recording_dir}/status/archived")
recorded_done_files.each do |recorded_done|
recorded_done_base = File.basename(recorded_done, '.done')
meeting_id = nil
break_timestamp = nil
meeting_id = nil
break_timestamp = nil
if match = /^([0-9a-f]+-[0-9]+)$/.match(recorded_done_base)
meeting_id = match[1]
elsif match = /^([0-9a-f]+-[0-9]+)-([0-9]+)$/.match(recorded_done_base)
meeting_id = match[1]
break_timestamp = match[2]
else
BigBlueButton.logger.warn("Recording done file for #{recorded_done_base} has invalid format")
next
end
attrs = {
'meeting_id': meeting_id,
'break_timestamp': break_timestamp,
}
BigBlueButton.logger.info("Enqueuing job to archive #{attrs.inspect}")
Resque.enqueue(BigBlueButton::Resque::ArchiveWorker, attrs)
FileUtils.rm_f(recorded_done)
if match = /^([0-9a-f]+-[0-9]+)$/.match(done_file)
meeting_id = match[1]
elsif match = /^([0-9a-f]+-[0-9]+)-([0-9]+)$/.match(done_file)
meeting_id = match[1]
break_timestamp = match[2]
else
BigBlueButton.logger.warn("Recording done file for #{done_file} has invalid format")
return
end
attrs = {
'meeting_id': meeting_id,
'break_timestamp': break_timestamp,
}
BigBlueButton.logger.info("Enqueuing job to archive #{attrs.inspect}")
Resque.enqueue(BigBlueButton::Resque::ArchiveWorker, attrs)
end
begin
@ -68,12 +61,23 @@ begin
redis_port = props['redis_workers_port'] || props['redis_port']
Resque.redis = "#{redis_host}:#{redis_port}"
BigBlueButton.logger.debug('Running rap-trigger...')
logger.debug('Running rap-trigger...')
archive_recorded_meetings(props)
recording_dir = props['recording_dir']
watch_dir = "#{recording_dir}/status/recorded/"
logger.info("Setting up inotify watch on #{watch_dir}")
notifier = INotify::Notifier.new
notifier.watch(watch_dir, :moved_to, :create) do |event|
next unless event.name.end_with?('.done')
BigBlueButton.logger.debug('rap-trigger done')
id = File.basename(event.name, '.done')
logger.info "Detected recording #{id}, starting the processing"
archive_recorded_meetings(id)
FileUtils.rm_f(event.absolute_name)
end
logger.info('Waiting for new recordings...')
notifier.run
rescue Exception => e
BigBlueButton.logger.error(e.message)
e.backtrace.each do |traceline|

View File

@ -7,3 +7,4 @@ ExecStart=/usr/local/bigbluebutton/core/scripts/rap-starter.rb
WorkingDirectory=/usr/local/bigbluebutton/core/scripts
User=bigbluebutton
Slice=bbb_record_core.slice
Restart=on-failure

View File

@ -1,4 +1,4 @@
[Unit]
Description=BigBlueButton recording & playback processing
Wants=bbb-rap-starter-worker.service bbb-rap-events-worker.service
Wants=bbb-rap-events-worker.service
StopWhenUnneeded=true