NAME

Krang::Schedule - Module for scheduling events in Krang.


SYNOPSIS

    use Krang::ClassLoader 'Schedule';
    # publish a story at a specific date
    $sched = pkg('Schedule')->new(
        object_type => 'story',
        object_id   => $story_id,
        action      => 'publish',
        repeat      => 'never',
        date        => $date
    );
    # publish a story at a specific date, specifying the version to be
    # published
    $sched = pkg('Schedule')->new(
        object_type => 'story',
        object_id   => $story_id,
        action      => 'publish',
        context     => [version => $version],
        date        => $date
    );
    # publish a story at a specific date, specifying a limit to the number of 
    # attempts, a delay (in seconds) between each attempt, and the ID for a user
    # who should be emailed after failure/success
    $sched = pkg('Schedule')->new(
        object_type => 'story',
        object_id   => $story_id,
        action      => 'publish',
        date        => $date,
        failure_max_tries => 4,    # try a maximum of 4 times before giving up
        failure_delay_sec => 600,  # wait 10 minutes between each try
        failure_notify_id => 2,    # if all 4 attempts fail, email user 2 to notify him/her
        success_notify_id => 2,    # if any attempt succeeds, email user 2 to notify him/her
    );
    # save the schedule entry to the database
    $sched->save();
    # get the ID for a schedule
    $schedule_id = $schedule->schedule_id;
    # Create an entry to publish a story every Monday at noon.
    $sched = pkg('Schedule')->new(
        object_type => 'story',
        object_id   => $story_id,
        action      => 'publish',
        repeat      => 'weekly',
        day_of_week => 1,
        hour        => 12,
        minute      => 0
    );
    # Create an entry to publish a story at noon every day.
    $sched = pkg('Schedule')->new(
        object_type => 'story',
        object_id   => $story_id,
        action      => 'publish',
        repeat      => 'daily',
        hour        => 12,
        minute      => 0
    );
    # Create an entry to publish a story every hour on the hour.
    $sched = pkg('Schedule')->new(
        object_type => 'story',
        object_id   => $story_id,
        action      => 'publish',
        repeat      => 'hourly',
        minute      => 0
    );
    # Create an entry to publish a story every hour on the hour.
    $sched = pkg('Schedule')->new(
        object_type => 'story',
        object_id   => $story_id,
        action      => 'publish',
        repeat      => 'hourly',
        minute      => 0
    );
    # get a list of schedule objects for a given story
    @schedules = pkg('Schedule')->find(
        object_type => 'story',
        object_id   => 1
    );
    # load a schedule object by ID
    ($schedule) = pkg('Schedule')->find(schedule_id => $schedule_id);
    # get the next execution time of a scheduled event
    $date = $schedule->next_run;
    # get the last execution time of a scheduled event
    $date = $schedule->last_run;
    # execute the task represented by the schedule object
    $success = $schedule->execute();
    # update the next_run field in the schedule object.
    $schedule->update_execution_time();
    # Find the default priority for a Krang::Schedule object
    $priority = pkg('Schedule')->determine_priority(schedule => $schedule);
    # or for the current object
    $priority = $schedule->determine_priority();


DESCRIPTION

This module provides the API into the Krang scheduler. It is responsible for handling events within Krang that have been scheduled by users. At this time, those events fall into one of three categories: sending alerts, publishing content (stories and/or media), and expiring content (stories and/or media).

Krang::Schedule is responsible for entering jobs into the system, and for handling the actual execution of a given job. Determining when to run a job, and the allocation of resources to run that job are handled by Krang::Schedule::Daemon.


INTERFACE