limit number of threads updating feeds

This commit is contained in:
Gwenhael Le Moine 2018-08-28 15:47:36 +02:00
parent aeecc5ce45
commit 43eac33c73
No known key found for this signature in database
GPG key ID: FDFE3669426707A7

20
n/nextcloud-server/nextcloud-news-updater.rb Normal file → Executable file
View file

@ -2,7 +2,8 @@
require "json"
require "thwait"
NC_ROOT="/srv/www/vhosts/nextcloud-server/htdocs"
NC_ROOT = "/srv/www/vhosts/nextcloud-server/htdocs".freeze
NB_THREADS = 2
def occ( command )
`php -f #{NC_ROOT}/occ #{command}`
@ -10,11 +11,16 @@ end
occ( 'news:updater:before-update' )
ThreadsWait.all_waits( JSON.parse( occ( 'news:updater:all-feeds' ) )["feeds"]
.map do |feed|
Thread.new do
occ( "news:updater:update-feed #{feed['id']} #{feed['userId']}" )
end
end )
feeds = JSON.parse( occ( 'news:updater:all-feeds' ) )["feeds"]
slices_size = (feeds.length / NB_THREADS).floor
ThreadsWait.all_waits( feeds.each_slice( slices_size ).to_a.map do |subfeeds|
Thread.new do
subfeeds.each do |feed|
occ( "news:updater:update-feed #{feed['id']} #{feed['userId']}" )
end
end
end )
occ( 'news:updater:after-update' )