Skip to content

Commit

Permalink
docs: Some documentation improvements (#12)
Browse files Browse the repository at this point in the history
Signed-off-by: starry-shivam <starry@krsh.dev>
  • Loading branch information
starry-shivam authored Jun 20, 2024
1 parent 7087026 commit 31a1f2a
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 10 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ dependencies {

### Documentation 📑

> [!Note]
>
> Full documentation for all classes and functions in KDoc format can be
> found [here](https://javadoc.jitpack.io/com/github/Pool-Of-Tears/KtScheduler/latest/javadoc/index.html).
Here's a quick start:

```kotlin
Expand Down
12 changes: 7 additions & 5 deletions src/main/kotlin/dev/starry/ktscheduler/event/JobEventListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@

package dev.starry.ktscheduler.event


/**
* JobEventListener is an interface that is used to listen to the job events.
* Interface for listening to job events.
*/
interface JobEventListener {

/**
* This method is called when the job is completed.
* Called when a job completes successfully.
*
* @param event The event that is triggered when the job is completed.
* @param event The event associated with the completed job.
*/
fun onJobComplete(event: JobEvent)

/**
* This method is called when there is an error while executing the job.
* Called when a job encounters an error.
*
* @param event The event that is triggered when the job is started.
* @param event The event associated with the job error.
*/
fun onJobError(event: JobEvent)
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ class InMemoryJobStore : JobStore {
* @param nextRunTime The new next run time.
*/
override fun updateJobNextRunTime(jobId: String, nextRunTime: ZonedDateTime) {
jobs[jobId]?.let {
jobs[jobId] = it.copy(nextRunTime = nextRunTime)
}
jobs[jobId]?.let { jobs[jobId] = it.copy(nextRunTime = nextRunTime) }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ class CronTrigger(
private val daysOfWeek: Set<DayOfWeek>,
private val time: LocalTime
) : Trigger {

/**
* Returns the next run time based on the specified days of the week and time.
*
* @param currentTime The current time as a [ZonedDateTime].
* @param timeZone The time zone in which the trigger is operating.
* @return The next run time as a [ZonedDateTime].
*/
override fun getNextRunTime(currentTime: ZonedDateTime, timeZone: ZoneId): ZonedDateTime? {
var nextRunTime = currentTime.withZoneSameInstant(timeZone).with(time).withNano(0)
if (nextRunTime.isBefore(currentTime) || nextRunTime.isEqual(currentTime)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import java.time.ZonedDateTime
* @param time The [LocalTime] at which the trigger should fire each day.
*/
class DailyTrigger(private val time: LocalTime) : Trigger {

/**
* Gets the next run time based on the current time and the specified daily time.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import java.time.ZonedDateTime
* @param intervalSeconds The interval, in seconds, between each trigger execution.
*/
class IntervalTrigger(private val intervalSeconds: Long) : Trigger {

/**
* Gets the next run time based on the current time and the specified interval.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import java.time.ZonedDateTime
* @param runAt The [ZonedDateTime] at which the trigger should fire.
*/
class OneTimeTrigger(private val runAt: ZonedDateTime) : Trigger {

/**
* Gets the next run time based on the current time and the specified run time.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class CoroutineExecutorTest {
trigger = trigger,
nextRunTime = ZonedDateTime.now(),
dispatcher = UnconfinedTestDispatcher(testScheduler),
callback = { throw IllegalArgumentException("Error") },
callback = { throw IllegalArgumentException("Error") },
)

val onSuccess: () -> Unit = { fail("onSuccess should not be called") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class InMemoryJobStoreTest {
trigger = OneTimeTrigger(nextRunTime),
nextRunTime = nextRunTime,
dispatcher = Dispatchers.Default,
callback = { /* Do nothing */}
callback = { /* Do nothing */ }
)
}
}

0 comments on commit 31a1f2a

Please sign in to comment.