ScheduledJob

Represents a pairing of a Job with a schedule. This is a component that is utilized internally by Schedulers.

Constructors

this
this(Job job, JobSchedule schedule, long id, CurrentTimeProvider timeProvider)

Constructs a new pairing of a job and a schedule.

this
this(Job job, JobSchedule schedule, long id)

Constructs a new pairing of a job and a schedule, with the default system time provider.

Members

Functions

getId
long getId()

Gets the id for this scheduled job.

getJob
Job getJob()

Gets the job from this pairing.

getSchedule
JobSchedule getSchedule()

Gets the schedule from this pairing.

opCmp
int opCmp(Object other)

Compares two scheduled jobs, such that jobs whose next execution time is earlier, are considered greater than others.

Examples

Tests the functionality of comparing two scheduled jobs.

import std.experimental.logger;
import scheduled.schedules.one_time;

JobSchedule s1 = new OneTimeSchedule(msecs(50));
JobSchedule s2 = new OneTimeSchedule(msecs(500));
JobSchedule s3 = new OneTimeSchedule(msecs(2500));

class IncrementJob : Job {
    public uint x = 0;
    public void run() {
        x++;
        logf(LogLevel.info, "Incrementing counter to %d.", x);
    }
}
auto j = new IncrementJob;

ScheduledJob jobA = new ScheduledJob(j, s1, 1);
ScheduledJob jobA2 = new ScheduledJob(j, s1, 2);
ScheduledJob jobB = new ScheduledJob(j, s2, 3);
ScheduledJob jobC = new ScheduledJob(j, s3, 4);
assert(jobA > jobB);
assert(jobA >= jobA2 && jobA <= jobA2);
assert(jobB > jobC);
assert(jobA > jobC);

Meta