Commit 237a1eca authored by Paul Cammish's avatar Paul Cammish
Browse files

Merge branch 'buster_cron-fix' into 'buster-testing'

Fix output for sympl-crontab

See merge request sympl/sympl!111
parents ca259cb7 a499fdd0
sympl-cron (10.0.190719.0) stable; urgency=medium
* Updated sympl-crontab --test output
-- Paul Cammish <sympl@kelduum.net> Fri, 19 Jul 2019 12:07:00 +0100
sympl-cron (10.0.190621.0) stable; urgency=medium sympl-cron (10.0.190621.0) stable; urgency=medium
* Created Sympl v10.0 (Debian Buster) * Created Sympl v10.0 (Debian Buster)
......
...@@ -31,26 +31,6 @@ require 'net/smtp' ...@@ -31,26 +31,6 @@ require 'net/smtp'
require 'date' require 'date'
require 'time' require 'time'
#
# Additional methods for DateTime
#
class DateTime
#
# Return a string of self in the standard "YYYY-MM-DD hh:mm" format.
#
def iso8601
"%04i-%02i-%02i %02i:%02i" % [ year, month, day, hour, min ]
end
#
# Convert self into a Time.
#
def to_time
Time.local(year, month, day, hour, min, sec)
end
end
module Symbiosis module Symbiosis
# #
...@@ -123,19 +103,19 @@ module Symbiosis ...@@ -123,19 +103,19 @@ module Symbiosis
# #
def test(t = Time.now) def test(t = Time.now)
cron_env = @environment.merge(ENV){|k,o,n| o} cron_env = @environment.merge(ENV){|k,o,n| o}
puts "Environment\n"+"-"*72 puts "Environment\n"+"-"*79
%w(HOME LOGNAME PATH MAILTO).each do |k| %w(HOME LOGNAME PATH MAILTO).each do |k|
puts "#{k} = #{cron_env[k]}" puts "#{k} = #{cron_env[k]}"
end end
puts "="*72+"\n\n" puts "="*79+"\n\n"
puts "Jobs next due -- Local time #{t.iso8601}\n"+"-"*72 puts "Jobs next due -- Local time #{t.strftime('%Y-%m-%d %H:%M:%S')}\n"+"-"*79
puts ("%-20s" % "Date" ) + "Command" puts ("%-20s" % "Next Run Time" ) + "Command"
puts "-"*72 puts "-"*79
@records.each do |record| @records.each do |record|
n = record.next_due(t) n = record.next_due(t)
puts ("%-20s" % (n.nil? ? "** NEVER **" : n.iso8601))+record.command puts ("%-20s" % (n.nil? ? "** NEVER **" : n.strftime('%Y-%m-%d %H:%M')))+record.command
end end
puts "="*72 puts "="*79
end end
# #
...@@ -297,6 +277,7 @@ module Symbiosis ...@@ -297,6 +277,7 @@ module Symbiosis
# arguments fail to parse. # arguments fail to parse.
# #
def initialize(min, hour, mday, mon, wday, command) def initialize(min, hour, mday, mon, wday, command)
@min = parse_field(min, 0, 59) @min = parse_field(min, 0, 59)
@hour = parse_field(hour, 0, 23) @hour = parse_field(hour, 0, 23)
@mday = parse_field(mday, 1, 31) @mday = parse_field(mday, 1, 31)
...@@ -327,7 +308,6 @@ module Symbiosis ...@@ -327,7 +308,6 @@ module Symbiosis
# Returns true if the record should be run at time set by now. # Returns true if the record should be run at time set by now.
# #
def ready?(now = Time.now) def ready?(now = Time.now)
now = now.to_time
if @lazy_mday_wday_match if @lazy_mday_wday_match
min.include? now.min and min.include? now.min and
hour.include? now.hour and hour.include? now.hour and
...@@ -349,8 +329,9 @@ module Symbiosis ...@@ -349,8 +329,9 @@ module Symbiosis
# time in the 30 years after now. # time in the 30 years after now.
# #
def next_due(now = Time.now) def next_due(now = Time.now)
time = now.to_time time = now
orig_time = time orig_time = time
while !ready?(time) while !ready?(time)
# find the next minute that matches # find the next minute that matches
...@@ -443,7 +424,14 @@ module Symbiosis ...@@ -443,7 +424,14 @@ module Symbiosis
break break
end end
end end
time
# We want the *next* time it'll run, rather than the time right now.
if ready?(orig_time)
time + 60
else
time
end
end end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment