Syncthing scheduler idea

A scheduler for changing the rate limit at certain times is currently in the making (see issue #6130) I want to share my idea for an improvement

Do we even need the minute granularity?

0 … rate limit is off
1 … rate limit is on

so a business week 9-17 would look like this in config.xml

000000000111111111000000
000000000111111111000000
000000000111111111000000
000000000111111111000000
000000000111111111000000
000000000000000000000000
000000000000000000000000

The scheduler reads this config and simply keeps all days+hours that have a scheduled “1” in the memory. The “0” are not needed

Examples
Monday, 11:46 → there is a “1” for hour “11” in the config → rate limit on
Saturday, 20:53 → there is nothing in the memory config → rate limit off

GUI have 1 checkbox for each day/hour plus some conditional css if the checkbox is clicked e.g. has green background.

working mockup - yes, I work Saturdays :smile:
syncsched

1 Like

The UI looks good, but I don’t think we’ll store 0’s and 1’s in the config, as the format is not self explanatory, and not easily understandable by humans, so I’d probably stick with an array of time ranges when it’s on.

2 Likes

Thanks!
I understand what you mean, it would be sufficient to only store the “rate limit is on” days+hours combinations.

Building block for above table - repeat 168 times :slight_smile:

HTML

<div class="schedule">
  <input type="checkbox" class="hour" id="input-{day}-{hour}" />
  <label for="input-{day}-{hour}"></label>
</div>

CSS
the original checkbox input itself is hidden and a “:after” pseudo-element (in this case a square) is attached to the label.

.hour + label:after {
  border: 1px solid #ccc;
  content: '';
  display: inline-block;
  height: 16px; 
  width: 16px;
}

CSS magic

.hour:checked + label:after {
  background-color: #008000;
}

which means that if checkbox is checked, the following element after it is colored.
It works without extra Javascript

So we only need to come up with a simple (human readable?) way to store which day/hour is scheduled and a helper script the builds above table (= e.g. loops through all days/hours)

It’s not rocket science

type ScheduleEntry struct {
   StartHour
   EndHour
   Day DayOfWeek
}

type Schedule struct {
   Entries []ScheduleEntry
}

This would end up with the following in XML:

<schedule>
   <scheduleEntry startHour="9" endHour="15" day="Monday"/>
   <scheduleEntry startHour="9" endHour="15" day="Tuesday"/>
</schedule>