[Fusionforge-commits] r13405 - in trunk/src: common/include cronjobs
Alain Peyrat
aljeux at fusionforge.org
Thu May 19 20:14:01 CEST 2011
Author: aljeux
Date: 2011-05-19 20:14:01 +0200 (Thu, 19 May 2011)
New Revision: 13405
Added:
trunk/src/common/include/forge_events.php
trunk/src/cronjobs/job-restart.sh
trunk/src/cronjobs/job-server.pl
Log:
Live event system (experimental, not activated by default)
Added: trunk/src/common/include/forge_events.php
===================================================================
--- trunk/src/common/include/forge_events.php (rev 0)
+++ trunk/src/common/include/forge_events.php 2011-05-19 18:14:01 UTC (rev 13405)
@@ -0,0 +1,62 @@
+<?php
+
+abstract class ForgeEvent extends Plugin {
+ function ForgeEvent () {
+ $this->Plugin() ;
+ $this->name = "event" ;
+ $this->text = "event" ;
+ $this->hooks[] = 'group_approve';
+ $this->hooks[] = 'scm_admin_update';
+ $this->hooks[] = 'site_admin_option_hook';
+ }
+
+ abstract function trigger_job($name);
+
+ function group_approve($params) {
+ return $this->trigger_job('create_scm_repos');
+ }
+
+ function scm_admin_update($params) {
+ return $this->trigger_job('create_scm_repos');
+ }
+
+ function site_admin_option_hook($params) {
+ $action = getStringFromRequest('action');
+ echo '<li><a name="jobs"></a>'.util_make_link('/admin/?action=listjobs#jobs', _('Jobs'))."\n";
+ if ($action == 'listjobs') {
+ echo '<ul>';
+ echo '<li>'.util_make_link('/admin/?action=runjobs&job=create_scm_repos#jobs', _('Create SCM Repositories')).'</li>'."\n";
+ echo '<li>'.util_make_link('/admin/?action=runjobs&job=scm_update#jobs', _('Upgrade Forge Software')).'</li>'."\n";
+ echo '</ul>';
+ }
+ echo '</li>';
+ if ($action == 'runjobs') {
+ $job = getStringFromRequest('job');
+ $job = util_ensure_value_in_set($job, array('create_scm_repos', 'scm_update'));
+ $this->trigger_job($job);
+ }
+ echo '<li><a name="version"></a>'.util_make_link('/admin/?action=version#version', _('Version'))."\n";
+ if ($action == 'version') {
+ echo '<pre>';
+ if (is_dir("/opt/acosforge/.svn")) {
+ system("cd /opt/acosforge; svn info --config-dir /tmp 2>&1");
+ }
+ if (is_dir("/opt/acosforge/.git")) {
+ system("cd /opt/acosforge; git svn info 2>&1");
+ }
+ echo '</pre>'."\n";
+ }
+ echo '</li>';
+ }
+}
+
+class PgForgeEvent extends ForgeEvent {
+ function trigger_job($name) {
+ return db_query_params("NOTIFY $name", array());
+ }
+}
+
+register_plugin (new PgForgeEvent) ;
+
+$pm = plugin_manager_get_object() ;
+$pm->SetupHooks () ;
Added: trunk/src/cronjobs/job-restart.sh
===================================================================
--- trunk/src/cronjobs/job-restart.sh (rev 0)
+++ trunk/src/cronjobs/job-restart.sh 2011-05-19 18:14:01 UTC (rev 13405)
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ $(ps ax | grep -v grep | grep "job-server.pl" | wc -l) -eq 0 ]
+then
+ echo "job-server.pl Service not running, relauching."
+ nohup `dirname $0`/job-server.pl &
+fi
Property changes on: trunk/src/cronjobs/job-restart.sh
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/cronjobs/job-server.pl
===================================================================
--- trunk/src/cronjobs/job-server.pl (rev 0)
+++ trunk/src/cronjobs/job-server.pl 2011-05-19 18:14:01 UTC (rev 13405)
@@ -0,0 +1,54 @@
+#!/usr/bin/perl -w
+
+# Taken from an example script to use DBD::Pg to listen for async notifications
+# by andrew at supernews.net, but don't bother emailing me about it;
+# try #PostgreSQL on irc.freenode.net but read all the relevent
+# manpages first.
+
+use DBI;
+
+my $database_name;
+my $database_user;
+my $database_password;
+
+my $forge_get_config = "/opt/gforge/utils/forge_get_config";
+my $jobs_dir = "/opt/gforge/cronjobs";
+
+chomp($database_name = `$forge_get_config database_name`);
+chomp($database_user = `$forge_get_config database_user`);
+chomp($database_password = `$forge_get_config database_password`);
+
+my $dbh = DBI->connect("dbi:Pg:dbname=$database_name", $database_user, $database_password,
+ { RaiseError => 1, AutoCommit => 1 });
+
+$dbh->do("LISTEN create_scm_repos;");
+$dbh->do("LISTEN scm_update;");
+
+$sth=$dbh->prepare("INSERT INTO cron_history (rundate,job,output) values (?, ?, ?)");
+
+while (1)
+{
+ my $notifies = $dbh->func('pg_notifies');
+ if (!$notifies)
+ {
+ # No notifications received. So sleep waiting for data on the backend connection.
+ my $fd = $dbh->func('getfd');
+ my $rfds = '';
+ vec($rfds,$fd,1) = 1;
+ my $n = select($rfds, undef, undef, 30);
+
+ $notifies = $dbh->func('pg_notifies');
+ }
+ while ($notifies)
+ {
+ # the result from pg_notifies is a ref to a two-element array,
+ # with the notification name and the sender's backend PID.
+ my ($n,$p) = @$notifies;
+ $output = "Running: $jobs_dir/$n.php $p\n";
+ $output .= `$jobs_dir/$n.php 2>&1`;
+
+ $sth->execute(time(),903,$output);
+
+ $notifies = $dbh->func('pg_notifies');
+ }
+}
Property changes on: trunk/src/cronjobs/job-server.pl
___________________________________________________________________
Added: svn:executable
+ *
More information about the Fusionforge-commits
mailing list