-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: init basic worker for language
- Loading branch information
Showing
8 changed files
with
82 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/PickJob.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/AbstractWorker.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/LangWorker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package cc.unitmesh.pick.worker | ||
|
||
import cc.unitmesh.pick.picker.PickJob | ||
|
||
abstract class LangWorker { | ||
abstract fun addJob(job: PickJob) | ||
abstract suspend fun start() | ||
} |
15 changes: 0 additions & 15 deletions
15
unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerDispatch.kt
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cc.unitmesh.pick.worker | ||
|
||
import cc.unitmesh.pick.picker.PickJob | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import org.archguard.rule.common.Language | ||
|
||
class WorkerManager { | ||
private val workers: Map<Language, LangWorker> = mapOf( | ||
Language.JAVA to JavaLangWorker(), | ||
) | ||
|
||
fun addJob(job: PickJob) { | ||
val language = job.language.toSupportLanguage() | ||
// print job serial | ||
val worker = workers[language] | ||
worker?.addJob(job) | ||
} | ||
|
||
suspend fun runAll() { | ||
workers.forEach { (_, worker) -> | ||
worker.start() | ||
} | ||
} | ||
} | ||
|
||
private fun String.toSupportLanguage(): Language? { | ||
return when (this.lowercase()) { | ||
"java" -> Language.JAVA | ||
"kotlin" -> Language.KOTLIN | ||
"csharp", "c#" -> Language.CSHARP | ||
"python" -> Language.PYTHON | ||
"go" -> Language.GO | ||
"typescript" -> Language.TYPESCRIPT | ||
"javascript" -> Language.JAVASCRIPT | ||
else -> null | ||
} | ||
} |