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

Stepford::Scheduler - Takes a set of steps and figures out what order to run them in

VERSION

version 0.000001

SYNOPSIS

    use Stepford::Scheduler;

    my @steps = (
        My::Step::Step1->new(
            name => 'step 1',
            ...
        ),
        My::Step::Step2->new(
            name => 'step 2',
            ...
        ),
        My::Step::MakeSomething->new(
            name         => 'Generate a file',
            dependencies => [ 'step 1', 'step 2' ],
        ),
    );

    my $target_step = $steps[-1];

    # Runs all the steps needed to get to the $final_step.
    Stepford::Scheduler->new(
        steps => \@steps,
    )->run($final_step);

DESCRIPTION

This class takes a set of objects which do the Stepford::Role::Step role and figured out in what order they should be run in order to get to a final step.

Steps which are up to date are skipped during the run, so no unnecessary work is done.

METHODS

This class provides the following methods:

Stepford::Scheduler->new(...)

This returns a new scheduler object.

It accepts a single argument, steps. This should be an array reference containing one or more objects which do the Stepford::Role::Step role.

The constructor checks for circular dependencies among the steps and will throw a Stepford::Error exception if it finds one.

$scheduler->run($step)

Given a step object, the scheduler creates an execution plan of all the steps needed to get to that step.

For each step, the scheduler checks if it is up to date compared to its dependencies (as determined by the $step->last_run_time() method. If the step is up to date, it is skipped, otherwise the scheduler calls $step->run() on the step.

$scheduler->steps()

This methods returns a list of the steps in the scheduler.

AUTHOR

Dave Rolsky <drolsky@maxmind.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by MaxMind, Inc..

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.