mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2009-04-12 06:33 am

[dw-free] Change worker-manager to use YAML configuration for changing jobs by machine. Need this f

[commit: http://hg.dwscoalition.org/dw-free/rev/df6817c04b7c]

Change worker-manager to use YAML configuration for changing jobs by
machine. Need this for production, easier than having separate
configuration files for every machine.

Patch by [staff profile] mark.

Files modified:
  • bin/worker-manager
  • etc/workers.conf
--------------------------------------------------------------------------------
diff -r b9fac8fd82c5 -r df6817c04b7c bin/worker-manager
--- a/bin/worker-manager	Sun Apr 12 06:09:49 2009 +0000
+++ b/bin/worker-manager	Sun Apr 12 06:33:41 2009 +0000
@@ -11,6 +11,7 @@
 
 use strict;
 use POSIX qw/ :sys_wait_h /;
+use YAML;
 
 # daemonize ourselves unless debugging
 my $debug = $ARGV[0] eq '--debug' ? 1 : 0;
@@ -41,14 +42,18 @@ sub load_config {
     my $fn = "$ENV{LJHOME}/etc/workers.conf";
     return unless -e $fn;
 
+    my $conf = YAML::LoadFile( $fn )
+        or die "Unable to read YAML formatted config: $fn\n";
+
+    my $hostname = `hostname`;
+    $hostname =~ s/^([^.]+)\..+\r?\n$/$1/;
+    die "Unable to get current hostname\n"
+        unless $hostname;
+
     my %jobs;
 
-    open FILE, "<$fn" or return;
-    foreach my $line (<FILE>) {
-        $line =~ s/\#.*$//;
-        next unless $line =~ /^(.+?)\s+(\d+)/;
-
-        my ($path, $ct) = ($1, $2);
+    foreach my $job ( keys %{ $conf->{all} || {} }, keys %{ $conf->{$hostname} || {} } ) {
+        my ( $path, $ct ) = ( $job, $conf->{$hostname}->{$job} || $conf->{all}->{$job} );
         my @fns = ( $path, "$ENV{LJHOME}/$path", "$ENV{LJHOME}/bin/worker/$path" );
         foreach my $ffn ( @fns ) {
             if ( -e $ffn ) {
@@ -57,8 +62,7 @@ sub load_config {
                 last;
             }
         }
-    }   
-    close FILE;
+    }
 
     return \%jobs;
 }
diff -r b9fac8fd82c5 -r df6817c04b7c etc/workers.conf
--- a/etc/workers.conf	Sun Apr 12 06:09:49 2009 +0000
+++ b/etc/workers.conf	Sun Apr 12 06:33:41 2009 +0000
@@ -1,7 +1,23 @@ esn-fired-event 1
-esn-fired-event 1
-esn-process-sub 1
-send-email 1
-esn-cluster-subs 1
-lazy-cleanup 1
-import-scheduler 1
-content-importer 1
+# to run jobs on every server that runs a worker-manager, put
+# the job name and the count here
+
+all:
+    esn-fired-event: 1
+    esn-process-sub: 1
+    send-email: 1
+    esn-cluster-subs: 1
+    lazy-cleanup: 1
+    import-scheduler: 1
+    content-importer: 1
+
+# alternately, if you want to run jobs on a particular hostname, or
+# alter how many jobs you run on a host, do it with the hostname
+
+dfw-lb01:
+    lazy-cleanup: 5
+    birthday-notify: 1
+
+# net result of the above: if you run worker-manager on dfw-foobar01
+# there will be 1 lazy-cleanup process and 0 birthday-notify jobs, but
+# if you run on dfw-lb01 then we will get 5 lazy-cleanup and one of
+# the birthday notifier
--------------------------------------------------------------------------------