The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Schedule::SoftTime - Scheduling functions (designed) for link checking

SYNOPSIS

       $sched = new Schedule::SoftTime, sched.db;
       $sched->schedule("last", 400);
       $sched->schedule("first", 200);
       my ($time, $name) = $sched->first_item();
	     "first"
       my ($time, $name) = $sched->next_item();
	     "last"

DESCRIPTION

This is a class to implement an `I'll get round to you when I can be bothered' scheduler. It's based on the queue system in our banks shops and some doctors I've been to. You turn up any time you want, but then you have to wait till everyone else who was there before you has been dealt with. The idea is to let the items being scheduled do so at any free time they wish and then worry about resource requirements later. If we can't handle some items when they were scheduled, they just queue until they can be handled.

The functions provided are

first_item() - give out the next object which should be checked if
any (first on the queue)
next_item() - give out the item after the last we gave out
schedule(time, string) - schedule an object for testing
unschedule(string) - unschedule an object

potentially you would want

schedule_priority - put an object in as soon as reasonable

   (simulates an old person coming in and asking to skip to the
    front of the queue)

but we haven't implemented that...

To guarantee that eventually each queue member gets to the front, I suggest that you never schedule something in the past..

We allow prioritisation by putting identifiers in at whatever time they ask for.

The time an object is scheduled for represents the first time it could be scheduled for checking. How close to reality it is depends on how bad the backlog is. We only allow one particular item to be scheduled per second.

If you have sufficient resources, you should be able to clear the backlog no matter what and the schedule will match reality.

If you are rude (always schedule identifiers for immediate checking) or underresourced this will degenerate to a queue in which the back end is a little disorganised (but in a helpful friendly kind of way).

If there is some level of lookahead into the queue (for example so that you can check identifiers on other sites whilst waiting for the longer robot exclusion period on one site), you should make sure that you don't make the situation of the first identifier worse.

METHODS

new Schedule::SoftTime filename

The new function sets up a schedule object using the file given as an argument for it's storage.

schedule

Schedule::SoftTime takes a identifier, and schedules it as soon after the time given as possible. We never schedule backwards in time.. That could be implemented by unscheduling then trying again with an earlier time..

unschedule

Remove whatever identifier is in a schedule slot using the schedule time.

first_item

Give out the first item that should be scheduled (probably overdue)

next_item

Give out the first item that should be scheduled (probably overdue)

THE FUTURE

What might be neat is an event dispatcher which interfaces with Cron. This would keep running when the next item in the schedule is within a few minutes, but would stop completely when there is a long time to wait and be restarted by cron.

Also useful would be a way to create scheduled (sic) down time. This would allow us to not allow link checking during busy times of the day. A way to avoid a sudden start up at the time of the end of the sudden down time would also be useful.