Skip to content

Commit

Permalink
feat: update for context
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 18, 2023
1 parent 104ed32 commit ad760f0
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import cc.unitmesh.pick.prompt.Instruction
import cc.unitmesh.pick.worker.worker.JavaWorker
import cc.unitmesh.pick.worker.worker.TypescriptWorker
import org.archguard.rule.common.Language
import org.slf4j.Logger

class WorkerManager(workerContext: WorkerContext) {
private val workers: Map<Language, LangWorker> = mapOf(
Expand All @@ -13,17 +14,30 @@ class WorkerManager(workerContext: WorkerContext) {
Language.JAVASCRIPT to TypescriptWorker(workerContext),
)

private val logger: Logger = org.slf4j.LoggerFactory.getLogger(WorkerManager::class.java)

fun addJob(job: InstructionFileJob) {
if (job.fileSummary.binary || job.fileSummary.generated || job.fileSummary.weightedComplexity > 1000) {
if (job.fileSummary.complexity > 100) {
logger.info("skip file ${job.fileSummary.location} for complexity ${job.fileSummary.complexity}")
return;
}
if (job.fileSummary.binary || job.fileSummary.generated || job.fileSummary.minified) {
return
}

// if the file size is too large, we just try 64k
if (job.fileSummary.bytes > 1024 * 64) {
logger.info("skip file ${job.fileSummary.location} for size ${job.fileSummary.bytes}")
return;
}

val language = job.fileSummary.language.toSupportLanguage()
val worker = workers[language]
worker?.addJob(job)
val worker = workers[language] ?: return
logger.info("add file:" + job.fileSummary.location)
worker.addJob(job)
}

suspend fun runAll() : List<Instruction> {
suspend fun runAll(): List<Instruction> {
return workers.map { (_, worker) ->
try {
worker.start()
Expand Down

0 comments on commit ad760f0

Please sign in to comment.