#
# Time table for gathering scheduler
#
# The scheduler works in cycles, each cycle consists of $cycle_slots
# time slots with duration $slot_time seconds. When any error occurs
# (i.e., any of the commands returns with a non-zero exit code or it
# receives a fatal signal), the scheduler stops and it sends a report
# by e-mail.
#
# This file contains three types of lines:
#    - comments (empty lines and lines starting with "#")
#    - variable assignments (Perl commands starting with a dollar sign)
#    - command definitions (see below)
#

# Log file to use (STDERR if undefined)
# Can contain strftime conversions; re-opened at start of each slot.
$logfile = "log/scheduler-%Y%m%d";

# Slots per cycle
$cycle_slots = 7;

# Length of a slot [sec]
$slot_time = 86400;

# We align cycle starts on a multiple of $cycle_alignment [sec] since $cycle_epoch.
# $cycle_alignment must be at most $cycle_slots * $slot_time
$cycle_epoch = POSIX::mktime(0,1,8,8,9,101);
$cycle_alignment = 7*86400;

# If any slot is shorter than $slot_min sec, it's left out and we just wait
# for the next one. This can happen with the first slot on startup and also
# when some slot (e.g., indexing taking a lot of time) exceeds its length
# too much.
$slot_min = 14400;

# When the scheduler starts running, it can run a single out-of-order
# slot before resuming normal operation.
# (this can be also set from the command line when starting the scheduler).
$exception = "s";

# Mail address to send error notifications to (optional)
#$error_mail = "mj\@ucw.cz";

# Mail address to send progress reports to after every slot (optional)
#$progress_mail = "mj\@ucw.cz";

# Tracing of commands executed
$trace = 1;

# If SIGTERM is to be sent after less than $min_run_time seconds,
# the whole command is skipped.
$min_run_time = 1500;

# Special slots for which $slot_min and waiting at the end don't apply (a regex)
$special_slots = "[si]";

# File to put name of the current slot to
$slot_file = "lock/scheduler.slot";

# The list of commands. All commands whose <slot-regex> matches the current
# time slot number are executed in their listed order. If the command doesn't
# finish in <tout> seconds, the scheduler stops, but it leaves the command
# running. If <term> is specified, the scheduler sends SIGTERM to the command
# <term> seconds before the end of the current time slot; all such commands
# have their <tout> measured from sending of the SIGTERM, not from the start.
# Slot-regex "DOWN" matches scheduler shutdown.

# <slot-regex>	[<term>+]<tout>	<command>
[^0-9]		3600		bin/scontrol stop
[^0-9]		3600		rm -rf tmp/*
[^0-9]		3600		bin/scontrol start
[^0-9]		86400		bin/grecover
[0-9f]*		3600		bin/sizer db/*
[0f]		86400		bin/expire
[1-9].*		28800		bin/expire -q
.*		3600		bin/sizer db/*
[1i]		172800		bin/indexer -SIndexer.Directory=index.new
[1i]		3600		bin/scontrol swap
#[2i]		86400		bin/send-index sherlock1 run-2.3 index index
#[0-9fi]*	3600		bin/analyze-log
#.*		3600		bin/plot-log --suffix short --join-all="[0-9].*" --max-age=4 --quants 600 --force
#.*		3600		bin/plot-log --suffix long --join-all="[0-9].*" --max-age=28 --quants 3600 --force
.*		3600		bin/rotate-log 1 365 log/gatherd-*
.*		3600		bin/rotate-log 10000 365 log/scheduler-*
.*		3600		bin/rotate-log 10000 365 log/sherlockd-*
[0-9fg]*	300+100000	bin/gatherd
DOWN		3600		bin/scontrol stop

# Out-of-order slots we use:
#	s	normal scheduler startup
#	f	do a full expire
#	i	do an index build
#	g	avoid expiration, only gather
