Index: pgagent.sql =================================================================== RCS file: /projects/pgagent/pgagent.sql,v retrieving revision 1.5 retrieving revision 1.6 diff -Lpgagent.sql -Lpgagent.sql -u -w -r1.5 -r1.6 --- pgagent.sql +++ pgagent.sql @@ -151,13 +151,14 @@ jscmonthdays ALIAS FOR $7; jscmonths ALIAS FOR $8; - nextrun timestamptz := ''1970-01-01 00:00:00-00''; - runafter timestamptz := ''1970-01-01 00:00:00-00''; + nextrun timestamp := ''1970-01-01 00:00:00-00''; + runafter timestamp := ''1970-01-01 00:00:00-00''; bingo bool := FALSE; gotit bool := FALSE; foundval bool := FALSE; daytweak bool := FALSE; + minutetweak bool := FALSE; i int2 := 0; d int2 := 0; @@ -373,7 +374,12 @@ -- otherwise look for the next minute matching or after the current one. IF (nextyear > date_part(''YEAR'', runafter) OR nextmonth > date_part(''MONTH'', runafter) OR nextday > date_part(''DAY'', runafter) OR nexthour > date_part(''HOUR'', runafter) OR daytweak = TRUE) THEN nextminute := 0; - FOR i IN 1 .. 60 LOOP + IF minutetweak = TRUE THEN + d := 1; + ELSE + d := date_part(''YEAR'', runafter)::int2; + END IF; + FOR i IN d .. 60 LOOP IF jscminutes[i] = TRUE THEN nextminute := i - 1; foundval := TRUE; @@ -475,7 +481,7 @@ END LOOP; -- OK, is the correct weekday selected, or a wildcard? - IF (jscweekdays[date_part(''DOW'', nextrun)] = TRUE OR gotit = FALSE) THEN + IF (jscweekdays[date_part(''DOW'', nextrun) + 1] = TRUE OR gotit = FALSE) THEN -- Check for exceptions SELECT INTO d jexid FROM pgagent.pga_exception WHERE jexscid = jscid AND ((jexdate = nextrun::date AND jextime = nextrun::time) OR (jexdate = nextrun::date AND jextime IS NULL) OR (jexdate IS NULL AND jextime = nextrun::time)); @@ -483,6 +489,8 @@ -- Nuts - found an exception. Increment the time and try again runafter := nextrun + INTERVAL ''1 Minute''; bingo := FALSE; + minutetweak := TRUE; + daytweak := FALSE; ELSE bingo := TRUE; END IF; @@ -490,12 +498,15 @@ -- We''re on the wrong week day - increment a day and try again. runafter := nextrun + INTERVAL ''1 Day''; bingo := FALSE; + minutetweak := FALSE; daytweak := TRUE; END IF; ELSE runafter := nextrun + INTERVAL ''1 Minute''; bingo := FALSE; + minutetweak := TRUE; + daytweak := FALSE; END IF; END LOOP;