slackbuilds/n/nextcloud-server/nextcloud-news-updater.rb

34 lines
916 B
Ruby
Raw Permalink Normal View History

#!/usr/bin/env ruby
# frozen_string_literal true
require "json"
require "thwait" # gem install e2mmap thwait
2018-08-28 15:47:36 +02:00
NC_ROOT = "/srv/www/vhosts/nextcloud-server/htdocs".freeze
NB_THREADS = 2
def occ( command )
`php -f #{NC_ROOT}/occ #{command}`
end
occ( 'news:updater:before-update' )
2020-10-01 10:31:50 +02:00
users = JSON.parse( occ( 'user:list --output=json' ) )
2018-08-28 15:47:36 +02:00
2020-10-01 10:31:50 +02:00
users.keys.each do |userId|
feeds = JSON.parse( occ( "news:feed:list #{userId}" ) )
2018-08-28 15:47:36 +02:00
2020-10-01 10:31:50 +02:00
next if feeds.empty?
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 #{userId} #{feed['id']}" )
end
2018-08-28 15:47:36 +02:00
end
2020-10-01 10:31:50 +02:00
end )
end
occ( 'news:updater:after-update' )