Skip to content

Commit

Permalink
add jobmeta parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenz33 committed Oct 10, 2023
1 parent 566d2c8 commit 3fffff5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package doradilla.back
import akka.util.Timeout
import doracore.api.JobApi
import doracore.core.driver.DriverActor.{FSMDecrease, FSMIncrease}
import doracore.core.msg.Job.{JobMsg, JobRequest, JobResult}
import doracore.core.msg.Job.{JobMeta, JobMsg, JobRequest, JobResult}
import doracore.tool.receive.ReceiveActor
import doracore.util.{AppDebugger, CNaming}
import doracore.vars.ConstVars
import javax.print.attribute.standard.JobName

import javax.print.attribute.standard.JobName
import scala.concurrent.{ExecutionContext, Future}

/**
Expand All @@ -34,10 +34,11 @@ trait NamedJobRunner {
def runNamedProcessCommand(processJob: JobMsg,
jobName:String,
timeout: Timeout = ConstVars.longTimeOut,
priority: Option[Int] = None)(implicit ex: ExecutionContext): Future[JobResult] = {
priority: Option[Int] = None,
metaOpt:Option[JobMeta] =None)(implicit ex: ExecutionContext): Future[JobResult] = {
val jobApi = getNamedJobApi(jobName)
val receiveActor = jobApi.actorSystem.actorOf(ReceiveActor.receiveActorProps, CNaming.timebasedName("Receive"))
val processJobRequest = JobRequest(processJob, receiveActor, jobApi.processTranActor, priority)
val processJobRequest = JobRequest(processJob, receiveActor, jobApi.processTranActor, priority,metaOpt)
getProcessCommandFutureResult(processJobRequest, jobApi.defaultDriver, receiveActor,timeout)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ trait ProcessCommandRunner extends AskProcessResult with GetBlockIOExcutor with
def runProcessCommand(processJob: JobMsg,
backendServerOpt: Option[BackendServer] = None,
timeout: Timeout = ConstVars.longTimeOut,
priority: Option[Int] = None)(implicit ex: ExecutionContext): Future[JobResult] = {
priority: Option[Int] = None,
metaOpt:Option[JobMeta] =None)(implicit ex: ExecutionContext): Future[JobResult] = {
val backendServer = getBackendServer()
val resultOpt = for (driverService <- backendServer.getActorProxy(Const.driverServiceName);
processTranService <- backendServer.getActorProxy(Const.procssTranServiceName))
yield {
val actorSystem = backendServer.actorSystemOpt.get
val receiveActor = actorSystem.actorOf(ReceiveActor.receiveActorProps, CNaming.timebasedName("Receive"))
val processJobRequest = JobRequest(processJob, receiveActor, processTranService, priority)
val processJobRequest = JobRequest(processJob, receiveActor, processTranService, priority,metaOpt)
getProcessCommandFutureResult(processJobRequest, driverService, receiveActor,timeout)
}
resultOpt.getOrElse(Future(JobResult(JobStatus.Failed, new Exception(JsError("Can't get service")))))
Expand Down
24 changes: 22 additions & 2 deletions doradilla-core/src/test/scala/app/NamedJobRunnerSpec.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package app

import doracore.ActorTestClass
import doracore.core.msg.Job.JobMsg
import doracore.core.msg.Job.{JobMeta, JobMsg}
import doracore.util.{ProcessService, ProcessServiceSpec}
import doracore.vars.ConstVars
import doradilla.back.BackendServer
import doradilla.conf.TestVars
import org.scalatest.Matchers

import scala.concurrent.Await
import scala.concurrent.{Await, Future}

/**
* For app in doradilla
Expand Down Expand Up @@ -54,6 +54,26 @@ class NamedJobRunnerSpec extends ActorTestClass with Matchers {
}
}

"Name Job with Meta" must{
"run job in sequece the sleep operation will block following operation and time out will go" in{
val job1 = TestVars.sleepProcessJob
BackendServer.runNamedProcessCommand(job1, "job13",metaOpt = Some(JobMeta("NewNameJob1")))
val job2 = TestVars.processJob
val resultFuture = BackendServer.runNamedProcessCommand(job2, "job13",metaOpt = Some(JobMeta("NewNameJob2")))
val result =
try{
Await.ready(resultFuture, timeout)
}catch {
case _:Throwable =>Future("TimeOutError")
}
result.map{
a =>
a shouldBe("TimeOutError")
println(a)
}
}
}

"use same driver when name same" in {
val job1 = TestVars.sleepProcessJob
val result1Future = BackendServer.runNamedProcessCommand(job1, "job3")
Expand Down

0 comments on commit 3fffff5

Please sign in to comment.