[interchange-cvs] interchange - heins modified 2 files

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Mon May 16 23:02:30 EDT 2005


User:      heins
Date:      2005-05-17 03:02:30 GMT
Modified:  lib/Vend Cron.pm Server.pm
Log:
* Add ability to run Jobs from cron. The idea of a delay is removed
  since you can schedule exactly when it will run. There is no queue
  action, as fitting it into the current queue setup is a bit difficult.

  Jobs are specified with:

  0 0 * * * * =standard hourly
  0 1 2 * * * =standard daily
  0 2 4 * * 7 =standard weekly
  0 0 3 1 * * =standard monthly

* Add separator of ";" for specifying multiple cron tasks on the same
  line.

* Think about the idea of a catalog-based cron. We should make that minute-based
  instead of seconds-based, for one thing. One possibility is to allow
  a :catalog_cron job which looks at the state of any Cron settings in
  catalogs and runs those as Jobs when appropriate.

* Actually it makes sense to use the Jobs facility for a lot of
  cron tasks, and I will think of the possibility of modifying
  run_jobs() to not have a catalog base.

Revision  Changes    Path
2.2       +7 -3      interchange/lib/Vend/Cron.pm


rev 2.2, prev_rev 2.1
Index: Cron.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Cron.pm,v
retrieving revision 2.1
retrieving revision 2.2
diff -u -r2.1 -r2.2
--- Cron.pm	16 May 2005 21:22:28 -0000	2.1
+++ Cron.pm	17 May 2005 03:02:30 -0000	2.2
@@ -1,6 +1,6 @@
 # Vend::Cron - Determine tasks to run based on time
 #
-# $Id: Cron.pm,v 2.1 2005/05/16 21:22:28 mheins Exp $
+# $Id: Cron.pm,v 2.2 2005/05/17 03:02:30 mheins Exp $
 #
 # Copyright (C) 2002-2005 Interchange Development Group
 #
@@ -22,7 +22,7 @@
 package Vend::Cron;
 
 use vars qw($VERSION);
-$VERSION = substr(q$Revision: 2.1 $, 10);
+$VERSION = substr(q$Revision: 2.2 $, 10);
 
 use POSIX qw(strftime);
 use Vend::Util;
@@ -67,7 +67,7 @@
 		}
 		push @cronobj, {
 			times => \@times,
-			things => [ Text::ParseWords::shellwords($thing) ],
+			things => [ split /\s*;\s*/, $thing ],
 			original => $_,
 		};
 	}
@@ -128,6 +128,7 @@
 	my %do;
 	my @do_before;
 	my @do_after;
+	my @cronjobs;
 
 	my $date = POSIX::strftime("time=%H:%M:%S", localtime($time));
 	for my $obj (@todo) {
@@ -137,6 +138,9 @@
 			if($j =~ s/^://) {
 				$do{$j} = 1;
 			}
+			elsif($j =~  s/^=//) {
+				push @cronjobs, $j;
+			}
 			elsif($j =~  s/^>//) {
 				push @do_after, $j;
 			}
@@ -150,8 +154,8 @@
 	my @out = \%do;
 	push @out, (scalar(@do_before) ? \@do_before : undef);
 	push @out, (scalar(@do_after) ? \@do_after : undef);
+	push @out, (scalar(@cronjobs) ? \@cronjobs : undef);
 	return @out;
-
 }
 
 sub housekeeping {



2.65      +18 -5     interchange/lib/Vend/Server.pm


rev 2.65, prev_rev 2.64
Index: Server.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Server.pm,v
retrieving revision 2.64
retrieving revision 2.65
diff -u -r2.64 -r2.65
--- Server.pm	16 May 2005 21:22:28 -0000	2.64
+++ Server.pm	17 May 2005 03:02:30 -0000	2.65
@@ -1,6 +1,6 @@
 # Vend::Server - Listen for Interchange CGI requests as a background server
 #
-# $Id: Server.pm,v 2.64 2005/05/16 21:22:28 mheins Exp $
+# $Id: Server.pm,v 2.65 2005/05/17 03:02:30 mheins Exp $
 #
 # Copyright (C) 2002-2003 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -26,7 +26,7 @@
 package Vend::Server;
 
 use vars qw($VERSION);
-$VERSION = substr(q$Revision: 2.64 $, 10);
+$VERSION = substr(q$Revision: 2.65 $, 10);
 
 use POSIX qw(setsid strftime);
 use Vend::Util;
@@ -1020,11 +1020,10 @@
 	my $do;
 	my $do_before;
 	my $do_after;
+	my $cronjobs;
 
-#my $date = POSIX::strftime("time=%H:%M:%S", localtime($now));
 	if($Global::HouseKeepingCron) {
-		($do, $do_before, $do_after) = Vend::Cron::housekeeping($now);
-#::logDebug("got housekeeping at $date do=" . ::uneval($do));
+		($do, $do_before, $do_after, $cronjobs) = Vend::Cron::housekeeping($now);
 	}
 	else {
 		$do = {
@@ -1273,6 +1272,20 @@
 			for my $jobref (@scheduled_jobs) {
 				eval {
 					run_jobs (@$jobref);
+				};
+
+				if($@) {
+					::logGlobal({ level => 'notice' }, $@);
+				}
+			}
+		}
+
+		if($cronjobs) {
+			for(@$cronjobs) {
+				s/^=//;
+				my (@job) = split /[\s,\0]+/, $_;
+				eval {
+					run_jobs (@job);
 				};
 
 				if($@) {








More information about the interchange-cvs mailing list