Skip to content

Allow for the ability to specify a last execution instant. #171

@kevincianfarini

Description

@kevincianfarini

This will help recover from downtime within processes that are supposed to have 100% uptime.

public fun Clock.schedulePulse(
    schedule: PulseSchedule,
    timeZone: TimeZone = TimeZone.UTC,
    lastExecution: Instant = now()
): Pulse {
    val flow = flow {
        var lastPulse: LocalDateTime = lastExecution.toLocalDateTime(timeZone)
        while (true) {
            val nextPulse = lastPulse.nextMatch(schedule)
            delayUntil(nextPulse, timeZone)
            emit(nextPulse.toInstant(timeZone))
            lastPulse = nextPulse
        }
    }
    return Pulse(flow)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions