limit number of threads updating feeds
This commit is contained in:
parent
aeecc5ce45
commit
43eac33c73
1 changed files with 13 additions and 7 deletions
20
n/nextcloud-server/nextcloud-news-updater.rb
Normal file → Executable file
20
n/nextcloud-server/nextcloud-news-updater.rb
Normal file → Executable 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' )
|
||||
|
|
Loading…
Reference in a new issue