Last active
August 28, 2018 13:49
-
-
Save gwenhael-le-moine/d283bea499c2477089408ca4b11908dd to your computer and use it in GitHub Desktop.
update nextcloud's news app feeds in a single ruby script without any dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "json" | |
require "thwait" | |
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' ) | |
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' ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment