Skip to content

Commit

Permalink
refactor: extract function for better code reuse in interal
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jan 5, 2024
1 parent 0b32427 commit b4e52ac
Showing 1 changed file with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,42 @@ interface LangWorker {
}
}

val result = jobs.map { job ->
val jobContext = contextFromJob(job, workerContext)
val result = executeJob().map {
outputFile.appendText(it.toString() + "\n")
it
}

val flatten = workerContext.codeContextStrategies.map { type ->
type.builder(jobContext).build()
}.flatten()
return@coroutineScope result
}

flatten.map {
outputFile.appendText(it.toString() + "\n")
}
/**
* Executes a job and returns a list of typed instructions.
*
* This method iterates over the list of jobs and creates a job context for each job using the provided worker context.
* It then iterates over the code context strategies of the worker context and builds a list of typed instructions
* using the job context and each code context strategy. The resulting list of typed instructions is flattened and returned.
*
* @return a list of typed instructions generated by executing the jobs
*/
fun executeJob(): List<TypedIns> {
return jobs.map { job ->
val jobContext = createJob(job, workerContext)

flatten
workerContext.codeContextStrategies.map { type ->
type.builder(jobContext).build()
}.flatten()
}.flatten()

return@coroutineScope result
}

fun contextFromJob(job: InstructionFileJob, workerContext: WorkerContext) = JobContext(
/**
* Creates a JobContext object based on the given InstructionFileJob and WorkerContext.
*
* @param job The InstructionFileJob object representing the job to be processed.
* @param workerContext The WorkerContext object containing the context information for the worker.
* @return A JobContext object containing the job, quality types, file tree, output configuration, completion types,
* maximum completion in one file, project context, and quality threshold.
*/
fun createJob(job: InstructionFileJob, workerContext: WorkerContext) = JobContext(
job,
workerContext.qualityTypes,
fileTree,
Expand Down

0 comments on commit b4e52ac

Please sign in to comment.