Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 11
java-version: 17
distribution: 'temurin'

- name: Detect modified subprojects
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ out/
/.run/publish kafka and run example.run.xml
/.kotlin
/buildSrc/.kotlin
**/node_modules/
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import kotlinx.kover.gradle.plugin.dsl.KoverReportExtension
import org.gradle.api.NamedDomainObjectCollection
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.wrapper.Wrapper
import org.gradle.kotlin.dsl.DependencyHandlerScope
import org.gradle.kotlin.dsl.findByType
Expand All @@ -30,6 +29,7 @@ import org.gradle.plugins.ide.idea.model.IdeaModel
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
import org.jlleitschuh.gradle.ktlint.KtlintExtension
import org.jlleitschuh.gradle.ktlint.tasks.KtLintCheckTask
import org.jlleitschuh.gradle.ktlint.tasks.KtLintFormatTask
Expand All @@ -54,7 +54,6 @@ open class Conventions : Plugin<Project> {
apply(project.plugin("ktlint"))
}
repositories {
mavenLocal()
mavenCentral()
maven {
url = uri("https://maven.pkg.github.com/flaxoos/flax-gradle-plugins")
Expand Down Expand Up @@ -120,12 +119,12 @@ open class Conventions : Plugin<Project> {
tasks.named("build") {
dependsOn(tasks.matching { it.name.matches(Regex("detekt(?!.*Baseline).*\\b(Main|Test)\\b\n")) })
}
tasks.withType(Test::class) {
tasks.withType<KotlinJvmTest> {
useJUnitPlatform()
}

tasks.withType<Wrapper> {
gradleVersion = "8.3"
gradleVersion = "8.11"
distributionType = Wrapper.DistributionType.BIN
}
extensions.findByType(KoverReportExtension::class)?.apply {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ github.repository.name=extra-ktor-plugins
kotlin.native.cacheKind.linuxX64=none
kotlin.native.ignoreDisabledTargets=true
gradle.publish.enable.module-metadata=true
version=2.1.3
version=2.2.1
gpr.user=flaxoos
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=2g
kotlin.mpp.applyDefaultHierarchyTemplate=false
51 changes: 25 additions & 26 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
[versions]
# Core technologies
kotlin = "2.0.20"
java = "11"
kotlinx-serialization = "1.7.3"
kotlinx-io = "0.3.0"
ksp = "1.9.10-1.0.13"
kotlin = "2.1.10"
java = "17"
kotlinx-serialization = "1.8.0"
kotlinx-io = "0.7.0"
ksp = "2.1.10-1.0.31"
reactor = "3.7.4"

# Web Framework
ktor = "3.0.0"
ktor = "3.1.1"

# Android
android = "8.1.0"

# Database
h2 = "2.2.224"
postgres = "42.6.0"
exposed = "0.44.0"
mongodb = "5.2.0"
h2 = "2.3.232"
postgres = "42.7.5"
exposed = "0.60.0"
mongodb = "5.3.1"

# Logging
logback = "1.5.12"
kotlin-logging = "5.1.0"
logging_capabilities = "0.11.1"

# Asynchronous and Concurrency
atomicfu = "0.25.0"
kotlinx-coroutines = "1.9.0"
atomicfu = "0.27.0"
kotlinx-coroutines = "1.10.1"

# Testing
#kotest = "6.0.0.M1"
kotest = "5.9.1"
kotest-stable = "5.9.1"
kotest-6 = "6.0.0.M1"
kotest-5 = "5.9.1"
kotest-test-containers = "2.0.2"
mockk = "1.13.4"
mockative = "2.0.1"
kmock = "0.3.0-rc08"
testcontainers = "1.19.8"
testcontainers = "1.20.6"
redis-testcontainers = "1.6.4"

# Code Quality and Coverage
Expand All @@ -47,7 +46,7 @@ koverBadge = "0.0.6"
detekt = "1.23.1"

# Date and Time
kotlinx-datetime = "0.4.0"
kotlinx-datetime = "0.6.2"

# Functional Programming
arrow = "1.2.4"
Expand All @@ -74,8 +73,8 @@ gradle-release = "3.0.2"
nexusPublish = "2.0.0"

# Miscellaneous
krontab = "2.2.1"
uuid = "0.8.1"
krontab = "2.7.2"
uuid = "0.8.4"

[libraries]
# Core libraries
Expand Down Expand Up @@ -128,11 +127,11 @@ mongodb-driver-kotlin-coroutine = { module = "org.mongodb:mongodb-driver-kotlin-
mongodb-bson-kotlinx = { module = "org.mongodb:bson-kotlinx", version.ref = "mongodb" }

# Testing libraries
kotest-runner-junit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
kotest-property = { module = "io.kotest:kotest-property", version.ref = "kotest" }
kotest-framework-datatest = { module = "io.kotest:kotest-framework-datatest", version.ref = "kotest-stable" }
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest-stable" }
kotest-framework-engine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" }
kotest-runner-junit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest-6" }
kotest-property = { module = "io.kotest:kotest-property", version.ref = "kotest-6" }
kotest-framework-datatest = { module = "io.kotest:kotest-framework-datatest", version.ref = "kotest-5" }
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest-6" }
kotest-framework-engine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest-6" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
mockk-agent-jvm = { module = "io.mockk:mockk-agent-jvm", version.ref = "mockk" }
mockative = { module = "io.mockative:mockative", version.ref = "mockative" }
Expand Down Expand Up @@ -170,7 +169,7 @@ kotlin-logging = { module = "io.github.oshai:kotlin-logging", version.ref = "kot
loggingCapabilities-gradlePlugin = { module = "dev.jacomet.gradle.plugins:logging-capabilities", version.ref = "logging_capabilities" }

# Testing plugins
kotestFrameworkMultiplatform-gradlePlugin = { module = "io.kotest:kotest-framework-multiplatform-plugin-gradle", version.ref = "kotest" }
kotestFrameworkMultiplatform-gradlePlugin = { module = "io.kotest:kotest-framework-multiplatform-plugin-gradle", version.ref = "kotest-6" }

# Documentation
dokka-gradlePlugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
Expand Down Expand Up @@ -221,7 +220,7 @@ dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
atomicfu = { id = "org.jetbrains.kotlinx.atomicfu", version.ref = "atomicfu" }

# Testing
kotest = { id = "io.kotest.multiplatform", version.ref = "kotest" }
kotest = { id = "io.kotest.multiplatform", version.ref = "kotest-6" }

# Ksp
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public open class TaskSchedulingConfiguration {
)
}

public fun addTaskManager(taskManagerConfiguration: TaskManagerConfiguration<*>) {
public fun addTaskManager(taskManagerConfiguration: TaskManagerConfiguration) {
taskManagers.add {
taskManagerConfiguration.createTaskManager(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import io.github.flaxoos.ktor.server.plugins.taskscheduling.tasks.Task
import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.server.application.Application
import io.ktor.utils.io.core.Closeable
import korlibs.time.DateFormat
import korlibs.time.DateFormat.Companion.FORMAT2
import korlibs.time.DateTime
import korlibs.time.TimeFormat.Companion.DEFAULT_FORMAT
import korlibs.time.parseLocal
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
import kotlin.jvm.JvmInline

private val logger = KotlinLogging.logger { }
Expand All @@ -22,9 +23,10 @@ public abstract class TaskManager<TASK_EXECUTION_TOKEN : TaskExecutionToken> : C
task: Task,
executionTime: DateTime,
) {
val runs =
task.concurrencyRange().map { concurrencyIndex ->
application.async {
task
.concurrencyRange()
.map { concurrencyIndex ->
application.launch {
logger.trace {
"${application.host()}: Attempting task execution at ${executionTime.format2()} for ${task.name} - $concurrencyIndex"
}
Expand All @@ -42,10 +44,7 @@ public abstract class TaskManager<TASK_EXECUTION_TOKEN : TaskExecutionToken> : C
null
}
}
}
runs.awaitAll().filterNotNull().forEach {
markExecuted(it)
}
}.joinAll()
}

/**
Expand All @@ -62,25 +61,22 @@ public abstract class TaskManager<TASK_EXECUTION_TOKEN : TaskExecutionToken> : C
concurrencyIndex: Int,
): TASK_EXECUTION_TOKEN?

/**
* Mark this task as, provided a key was acquired
*/
public abstract suspend fun markExecuted(key: TASK_EXECUTION_TOKEN)

public companion object {
public fun Application.host(): String = "Host ${environment.config.property("ktor.deployment.host").getString()}"

public fun DateTime.format2(): String = format(DateFormat.FORMAT2)
public fun DateTime.format2(): String = format(FORMAT2)

public fun DateTime.formatTime(): String = time.format(DEFAULT_FORMAT)

public fun String.format2ToDateTime(): DateTime = DateFormat.FORMAT2.parseLocal(this)
public fun String.format2ToDateTime(): DateTime = FORMAT2.parseLocal(this)
}
}

/**
* Configuration for [TaskManager]
*/
@TaskSchedulingDsl
public abstract class TaskManagerConfiguration<TASK_EXECUTION_TOKEN> {
public abstract class TaskManagerConfiguration {
/**
* The name of the task manager, will be used to identify the task manager when assigning tasks to it
* if none is provided, it will be considered the default one. only one default task manager is allowed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ public abstract class TaskLockManager<TASK_LOCK : TaskLock> : TaskManager<TASK_L
concurrencyIndex: Int,
): TASK_LOCK? = acquireLockKey(task, executionTime, concurrencyIndex)

override suspend fun markExecuted(key: TASK_LOCK) {
releaseLockKey(key)
}

/**
* Get permission to execute the task
*/
Expand All @@ -26,12 +22,7 @@ public abstract class TaskLockManager<TASK_LOCK : TaskLock> : TaskManager<TASK_L
executionTime: DateTime,
concurrencyIndex: Int,
): TASK_LOCK?

/**
* Release permission to execute the task
*/
protected abstract suspend fun releaseLockKey(key: TASK_LOCK)
}

@TaskSchedulingDsl
public abstract class TaskLockManagerConfiguration<TASK_LOCK> : TaskManagerConfiguration<TASK_LOCK>()
public abstract class TaskLockManagerConfiguration : TaskManagerConfiguration()
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,4 @@ public interface DatabaseTaskLock : TaskLock {
}

@TaskSchedulingDsl
public abstract class DatabaseTaskLockManagerConfiguration<DB_TASK_LOCK_KEY : DatabaseTaskLock> :
TaskLockManagerConfiguration<DB_TASK_LOCK_KEY>()
public abstract class DatabaseTaskLockManagerConfiguration : TaskLockManagerConfiguration()
Loading