aggregate: Add support for web-based triggering of aggregation for people stuck on shared hosting without cron. (Sheesh.) Enabled via the `aggregate_webtrigger` configuration optiom.

master
Joey Hess 2008-05-05 20:20:45 -04:00
parent 86c6f2b963
commit 1f88cad3a2
5 changed files with 110 additions and 57 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/perl
# Blog aggregation plugin.
# Feed aggregation plugin.
package IkiWiki::Plugin::aggregate;
use warnings;
@ -21,6 +21,9 @@ sub import { #{{{
hook(type => "preprocess", id => "aggregate", call => \&preprocess);
hook(type => "delete", id => "aggregate", call => \&delete);
hook(type => "savestate", id => "aggregate", call => \&savestate);
if (exists $config{aggregate_webtrigger} && $config{aggregate_webtrigger}) {
hook(type => "cgi", id => "aggregate", call => \&cgi);
}
} # }}}
sub getopt () { #{{{
@ -33,50 +36,80 @@ sub getopt () { #{{{
sub checkconfig () { #{{{
if ($config{aggregate} && ! ($config{post_commit} &&
IkiWiki::commit_hook_enabled())) {
# See if any feeds need aggregation.
loadstate();
my @feeds=needsaggregate();
return unless @feeds;
if (! lockaggregate()) {
debug("an aggregation process is already running");
return;
}
# force a later rebuild of source pages
$IkiWiki::forcerebuild{$_->{sourcepage}}=1
foreach @feeds;
# Fork a child process to handle the aggregation.
# The parent process will then handle building the
# result. This avoids messy code to clear state
# accumulated while aggregating.
defined(my $pid = fork) or error("Can't fork: $!");
if (! $pid) {
IkiWiki::loadindex();
# Aggregation happens without the main wiki lock
# being held. This allows editing pages etc while
# aggregation is running.
aggregate(@feeds);
IkiWiki::lockwiki;
# Merge changes, since aggregation state may have
# changed on disk while the aggregation was happening.
mergestate();
expire();
savestate();
IkiWiki::unlockwiki;
exit 0;
}
waitpid($pid,0);
if ($?) {
error "aggregation failed with code $?";
}
clearstate();
unlockaggregate();
launchaggregation();
}
} #}}}
sub cgi ($) { #{{{
my $cgi=shift;
if (defined $cgi->param('do') &&
$cgi->param("do") eq "aggregate_webtrigger") {
$|=1;
print "Content-Type: text/plain\n\n";
$config{cgi}=0;
$config{verbose}=1;
$config{syslog}=0;
print gettext("Aggregation triggered via web.")."\n\n";
if (launchaggregation()) {
IkiWiki::lockwiki();
IkiWiki::loadindex();
require IkiWiki::Render;
IkiWiki::refresh();
IkiWiki::saveindex();
}
else {
print gettext("Nothing to do right now, all feeds are up-to-date!")."\n";
}
exit 0;
}
} #}}}
sub launchaggregation () { #{{{
# See if any feeds need aggregation.
loadstate();
my @feeds=needsaggregate();
return unless @feeds;
if (! lockaggregate()) {
debug("an aggregation process is already running");
return;
}
# force a later rebuild of source pages
$IkiWiki::forcerebuild{$_->{sourcepage}}=1
foreach @feeds;
# Fork a child process to handle the aggregation.
# The parent process will then handle building the
# result. This avoids messy code to clear state
# accumulated while aggregating.
defined(my $pid = fork) or error("Can't fork: $!");
if (! $pid) {
IkiWiki::loadindex();
# Aggregation happens without the main wiki lock
# being held. This allows editing pages etc while
# aggregation is running.
aggregate(@feeds);
IkiWiki::lockwiki;
# Merge changes, since aggregation state may have
# changed on disk while the aggregation was happening.
mergestate();
expire();
savestate();
IkiWiki::unlockwiki;
exit 0;
}
waitpid($pid,0);
if ($?) {
error "aggregation failed with code $?";
}
clearstate();
unlockaggregate();
return 1;
} #}}}
sub needsbuild (@) { #{{{
my $needsbuild=shift;

8
debian/changelog vendored
View File

@ -1,3 +1,11 @@
ikiwiki (2.46) UNRELEASED; urgency=low
* aggregate: Add support for web-based triggering of aggregation
for people stuck on shared hosting without cron. (Sheesh.) Enabled
via the `aggregate_webtrigger` configuration optiom.
-- Joey Hess <joeyh@debian.org> Mon, 05 May 2008 19:34:51 -0400
ikiwiki (2.45) unstable; urgency=low
* toc: Add the table of contents at sanitize time, rather than at format

View File

@ -163,4 +163,8 @@ use IkiWiki::Setup::Standard {
# For use with the anonok plugin, a PageSpec specifying what
# pages anonymous users can edit
#anonok_pagespec => "*",
# For use with the aggregate plugin, to allow aggregation to be
# triggered via the web.
#aggregate_webtrigger => 1,
}

View File

@ -28,6 +28,14 @@ crontab entry:
*/15 * * * * ikiwiki --setup my.wiki --aggregate --refresh
Alternatively, you can allow `ikiwiki.cgi` to trigger the aggregation. You
should only need this if for some reason you cannot use cron, and instead
want to use a service such as [WebCron](http://webcron.org). To enable
this, enable on `aggregate_webtrigger` in your setup file. The url to
visit is `http://whatever/ikiwiki.cgi?do=aggregate_webtrigger`. Anyone
can visit the url to trigger an aggregation run, but it will only check
each feed if its `updateinterval` has passed.
## usage
Here are descriptions of all the supported parameters to the `aggregate`

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2008-05-05 15:06-0400\n"
"POT-Creation-Date: 2008-05-05 20:05-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -71,67 +71,67 @@ msgstr ""
msgid "You are banned."
msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:101
#: ../IkiWiki/Plugin/aggregate.pm:126
#, perl-format
msgid "missing %s parameter"
msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:128
#: ../IkiWiki/Plugin/aggregate.pm:153
msgid "new feed"
msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:142
#: ../IkiWiki/Plugin/aggregate.pm:167
msgid "posts"
msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:144
#: ../IkiWiki/Plugin/aggregate.pm:169
msgid "new"
msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:307
#: ../IkiWiki/Plugin/aggregate.pm:332
#, perl-format
msgid "expiring %s (%s days old)"
msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:314
#: ../IkiWiki/Plugin/aggregate.pm:339
#, perl-format
msgid "expiring %s"
msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:341
#: ../IkiWiki/Plugin/aggregate.pm:366
#, perl-format
msgid "processed ok at %s"
msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:345
#: ../IkiWiki/Plugin/aggregate.pm:370
#, perl-format
msgid "checking feed %s ..."
msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:350
#: ../IkiWiki/Plugin/aggregate.pm:375
#, perl-format
msgid "could not find feed at %s"
msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:365
#: ../IkiWiki/Plugin/aggregate.pm:390
msgid "feed not found"
msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:376
#: ../IkiWiki/Plugin/aggregate.pm:401
#, perl-format
msgid "(invalid UTF-8 stripped from feed)"
msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:382
#: ../IkiWiki/Plugin/aggregate.pm:407
#, perl-format
msgid "(feed entities escaped)"
msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:388
#: ../IkiWiki/Plugin/aggregate.pm:413
msgid "feed crashed XML::Feed!"
msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:462
#: ../IkiWiki/Plugin/aggregate.pm:487
#, perl-format
msgid "creating new page %s"
msgstr ""