Chronic

 view release on metacpan or  search on metacpan

CHANGES  view on Meta::CPAN

0.15 (June 04, 2004) 

    - Introduced the "InXs" constraint that combines the
      Inactivity constraint and the Xscreensaver constraint
      using an OR relationship.

    - Scheduler wait doesn't exceed 10 minutes. This is because
      a machine can hibernate (or chronicd backgrounded) in
      middle of a long sleep, causing scheduler_wait to exceed
      the intended sleep time. An upper limit ensure that
      chronicd will "self-correct" its timers every 10 minutes.

    - Added support for email notifications. notify =
      email@address as a task field will send notifications to
      email@address. Time values in the email notification are
      in human readable format. eg. 35 seconds, 4.52 days, etc. 
      [Feature Request #946816]

    - Fixed a bug in chrontab re-writing logic. We were missing
      the final ";" which could've caused a corrupted chrontab
      in certain cases.

docs/TemplateConstraint.pm  view on Meta::CPAN

        # level logic can turn debugging, on/off.

        'debug'     => $debug,                                 

        # ``wait'' is optional. If you don't modify the wait() method, you
        # can set this parameter and wait() will return it's current value
        # to the caller.

        'wait'      => 0,

        # ``timer'' is an optional timer, a lot of constraints use it. 

        'timer'     => new Schedule::Chronic::Timer ('down'), 

    }, $class;

}


sub init { 

    my ($self, $schedule, $task, @params) = @_; 
    return unless $self; 

docs/design.txt  view on Meta::CPAN


Chronic constraints-based scheduling algorithm: 

    The scheduler maintains three kinds of timers:

            ``constraint_wait'' - per constraint
            ``task_wait'' - per task
            ``scheduler_wait'' - per scheduler

        constraint_wait is what ::Constraint::wait() returns, immediately
        after the call to met().

        task_wait is the smallest of constraint_wait's for a
        task.

    When a constraint_wait <= 0, it's met() method is called to see if the
    constraint was met. wait() must be called after the met() function to
    determine the wait() before the constraint should be checked again
    (ie. before the next met() call). wait() should be called immediately
    after met(), since the wait() value is actually computed by met(), 
    and wait() just returns it.

    The scheduler also maintains an "active" timer for each constraint.
    This active value is number of seconds for which the constrain has
    been active.

    The algorithm is as follows: 

    1. sleep_for_unit_time()

    2. If scheduler_wait > 0, sleep(scheduler_wait);

    3. Choose the next task from the list.

docs/design.txt  view on Meta::CPAN

        
    4. For every constraint of the task: 

        a. Call ::constraint::met() followed by 
            ::constrain::wait()

        c. set time_wait to wait if wait > time_wait

        c. If met(),
 
            -> reset constraint_active timer if 
                not running
            -> if (constraint_active > reqd_active) 
                constraint_active
                    -> last_ran = time();
                    -> execute the program

        c. If not met(), 
            do nothing.

        d. Goto Slep 1.

lib/Schedule/Chronic.pm  view on Meta::CPAN

        # Walk over all tasks, checks constraints and execute tasks when
        # all constraints are met. This is section should end in

        TASK: 
        for my $task (@$schedule) {

            # print Dumper $task; 

            # A task has four components. A set of constraints, a
            # command to run when these constraints are met, the
            # last_ran time and a task wait timer which is the
            # maximum wait time returned by a constraint.

            my $constraints = $$task{constraints};
            my $task_wait   = $$task{_task_wait};
            my $command     = $$task{command};
            my $last_ran    = $$task{last_ran};
            my $uid         = $$task{_uid};
            my $only_once   = $$task{only_once};

            if ($last_ran > 0 and $only_once == 1) { 

lib/Schedule/Chronic/Constraint/DiskIO.pm  view on Meta::CPAN



sub new { 
    
    my ($class) = @_;

    return bless { 
        bi_threshold => 5,
        bo_threshold => 5,
        active       => 10,
        timer        => new Schedule::Chronic::Timer ('down'),
    }, $class;

}


sub init { 

    my ($self, $schedule, $task, $logger, $active, $bi_threshold, $bo_threshold) = @_;
    return unless $self; 

lib/Schedule/Chronic/Constraint/DiskIO.pm  view on Meta::CPAN

}


sub met { 

    my ($self) = @_;

    my ($bi, $bo) = $self->state();

    $self->debug("DiskIO: buffers in = $bi ($$self{bi_threshold}), " .
       "buffers out = $bo ($$self{bo_threshold}), timer = " . $$self{timer}->get());

    if ($bo <= $$self{bo_threshold} and $bi <= $$self{bi_threshold} ) { 

        $$self{timer}->set($$self{active}) unless 
            $$self{timer}->running();

        if ($$self{timer}->get() <= 0) { 
            return 1;
        } else { 
            return 0;
        }

    } 

    $$self{timer}->stop();
    return 0;

}


sub state { 

    my ($self) = @_;

    # Should we use the proc file system (/proc/stat) to gather

lib/Schedule/Chronic/Constraint/Inactivity.pm  view on Meta::CPAN


sub new { 

    my ($class) = @_;

    return bless {

        loadavg => new Schedule::Chronic::Constraint::Loadavg ($debug),
        diskio  => new Schedule::Chronic::Constraint::DiskIO  ($debug),

        # This class doesn't have its own timer. Timers are maintained by
        # DiskIO and Loadavg.

    }, shift 

}


sub init { 

    my ($self, $schedule, $task, $logger, $active) = @_;

lib/Schedule/Chronic/Constraint/Loadavg.pm  view on Meta::CPAN

use base qw(Schedule::Chronic::Base);


sub new { 
    
    my ($class) = @_;

    return bless { 
        active       => 60,
        load_avg     => 0.00,
        timer        => new Schedule::Chronic::Timer ('down'),
    }, $class;

}


sub init { 

    my ($self, $schedule, $task, $logger, $active, $load_avg) = @_;
    return unless ref $self;
   

lib/Schedule/Chronic/Constraint/Loadavg.pm  view on Meta::CPAN

sub met { 

    my ($self) = @_;

    my $load_avg = $self->state();

    $self->debug("  load average = $load_avg ($$self{load_avg})");

    if ($load_avg <= $$self{load_avg}) { 

        $$self{timer}->set($$self{active}) unless 
            $$self{timer}->running();

        if ($$self{timer}->get() <= 0) { 
            return 1;
        } else { 
            return 0;
        }

    }  

    $$self{timer}->stop();

    # Compute wait as a factor of the current load_avg and the required
    # load_avg. The wait should be bound between 5 and 120 seconds.
    # There ought to be a better algorithm to derive the wait... FIX.

    my $divisor = $$self{load_avg} == 0 ? 0.01 : $$self{load_avg};
    my $wait = int($load_avg/$divisor);
    $wait = 5 if $wait < 5;
    $wait = 120 if $wait > 120;

lib/Schedule/Chronic/Constraint/Xscreensaver.pm  view on Meta::CPAN

use base qw(Schedule::Chronic::Base);


sub new { 
    
    my ($class) = @_;

    return bless { 
        active       => 10,
        wait         => 5,
        timer        => new Schedule::Chronic::Timer ('down'),
    }, $class;

}


sub init { 

    my ($self, $schedule, $task, $logger, $active) = @_;
    return unless $self; 

lib/Schedule/Chronic/Constraint/Xscreensaver.pm  view on Meta::CPAN


    # $state values: 
    # 0 means no change
    # 1 means toggled to locked
    # 2 means toggled to unlocked

    my @states = ('NO CHANGE', 'LOCKED', 'UNLOCKED');

    $self->debug("  xscreensaver state = $states[$state]");

    if ($$self{timer}->running() and $state == 0) { 
        
        # We are still in locked mode.

        if ($$self{timer}->get() <= 0) { 
            return 1;
        } else { 
            $$self{wait} = $$self{timer}->get();
            $self->debug("  xscreensaver locked, " . $$self{timer}->get() . " seconds remain.");
            return 0;
        }

    }

    if ($$self{timer}->running() and $state == 2) { 

        # In unlocked mode.

        $$self{wait} = 5;
        $$self{timer}->stop();
        return 0;

    } 


    if (!$$self{timer}->running() and $state == 1) { 

        # Toggled into locked mode.

        $$self{timer}->set($$self{active});
        $$self{wait} = 0;
        return 0;

    }

    return 0;

}


lib/Schedule/Chronic/Tab.pm  view on Meta::CPAN


        # If there's no command, this task is useless to us.
        $good = 0 unless exists $task{command};

        if ($good) { 

            # Initialize the task.
            # 
            # Add a last_ran of 0 (execute soon as possible)
            # if a last_ran is not available. Create a 
            # task_wait timer and initialize other task 
            # parameters.

            $task{last_ran} = 0 unless exists $task{last_ran};
            $task{only_once} = 0 unless exists $task{only_once};
            $task{_task_wait} = new Schedule::Chronic::Timer ('down');
            $task{_task_wait}->set(0);
            $task{_uid} = $uid;
            $task{_chrontab} = $tab;
            $task{_last_rv} = 0;



( run in 0.357 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )