aggregate: Add support for web-based triggering of aggregation for people stuck...
authorJoey Hess <joey@kodama.kitenet.net>
Tue, 6 May 2008 00:20:45 +0000 (20:20 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Tue, 6 May 2008 00:20:45 +0000 (20:20 -0400)
IkiWiki/Plugin/aggregate.pm
debian/changelog
doc/ikiwiki.setup
doc/plugins/aggregate.mdwn
po/ikiwiki.pot

index cb165acd2a0e7bb2c647d990d7723bf18a33b291..a9c7447fa8faf6a082e714b84cd203f2c4e3355d 100644 (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,48 +36,78 @@ 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();
+               launchaggregation();
+       }
+} #}}}
 
-                       # 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;
+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();
                }
-               waitpid($pid,0);
-               if ($?) {
-                       error "aggregation failed with code $?";
+               else {
+                       print gettext("Nothing to do right now, all feeds are up-to-date!")."\n";
                }
+               exit 0;
+       }
+} #}}}
 
-               clearstate();
-               unlockaggregate();
+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 (@) { #{{{
index be6cb205c97e40301db689c484dd31845952ca91..9b5cfd1b32ec735157de36e99d6ec7213a1f96c3 100644 (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
index cbc4cbc9fd9943ebc056c7950a44b39dba61e3e2..33710d1d773b2175f77ec84effae0b9d170ef6f5 100644 (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,
 }
index d224516df5464c0a831120e4603236619748029d..aab5f079a79c54f9b67acea5e60f8a9fd3f1e64d 100644 (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`
index ad94f5acf61552e69d7643eaef3c6ff556972154..38a677eae9cce050c71900297a8c94a947da4f4b 100644 (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 ""