-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
768 additions
and
255 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,36 @@ | ||
package camundala.worker | ||
|
||
|
||
import scala.concurrent.duration.* | ||
|
||
|
||
trait JobWorker: | ||
def topic: String | ||
def timeout: Duration = 10.seconds | ||
|
||
protected def errorHandled(error: CamundalaWorkerError, handledErrors: Seq[String]): Boolean = | ||
error.isMock || // if it is mocked, it is handled in the error, as it also could be a successful output | ||
handledErrors.contains(error.errorCode.toString) || handledErrors.map( | ||
_.toLowerCase | ||
).contains("catchall") | ||
|
||
protected def regexMatchesAll( | ||
errorHandled: Boolean, | ||
error: CamundalaWorkerError, | ||
regexHandledErrors: Seq[String] | ||
) = | ||
errorHandled && regexHandledErrors.forall(regex => | ||
error.errorMsg.matches(s".*$regex.*") | ||
) | ||
|
||
protected def filteredOutput( | ||
outputVariables: Seq[String], | ||
allOutputs: Map[String, Any] | ||
): Map[String, Any] = | ||
outputVariables match | ||
case filter if filter.isEmpty => allOutputs | ||
case filter => | ||
allOutputs | ||
.filter: | ||
case k -> _ => filter.contains(k) | ||
|
||
end filteredOutput | ||
end JobWorker |
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
03-worker/src/main/scala/camundala/worker/WorkerClient.scala
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
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
12 changes: 12 additions & 0 deletions
12
03-worker/src/main/scala/camundala/worker/WorkerRegistry.scala
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,12 @@ | ||
package camundala.worker | ||
|
||
import zio.ZIO | ||
import zio.ZIO.* | ||
|
||
trait WorkerRegistry[T <: JobWorker]: | ||
def register(workers: Set[JobWorker]): ZIO[Any, Any, Any] = | ||
logInfo(s"Registering Workers for ${getClass.getSimpleName}") *> | ||
registerWorkers(workers.collect { case w: T => w }) | ||
|
||
protected def registerWorkers(workers: Set[T]): ZIO[Any, Any, Any] | ||
end WorkerRegistry |
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,33 @@ | ||
package camundala.worker | ||
|
||
import org.slf4j.{Logger, LoggerFactory} | ||
import zio.* | ||
import zio.logging.* | ||
import zio.logging.backend.SLF4J | ||
|
||
object ZioLogger: | ||
val logger = Runtime.removeDefaultLoggers >>> SLF4J.slf4j | ||
|
||
end ZioLogger | ||
|
||
case class Slf4JLogger(private val delegateLogger: Logger) extends WorkerLogger: | ||
|
||
def debug(message: String): Unit = | ||
if delegateLogger.isDebugEnabled then | ||
delegateLogger.debug(message) | ||
|
||
def info(message: String): Unit = | ||
if delegateLogger.isInfoEnabled then | ||
delegateLogger.info(message) | ||
|
||
def warn(message: String): Unit = | ||
if delegateLogger.isWarnEnabled then | ||
delegateLogger.warn(message) | ||
|
||
def error(err: CamundalaWorkerError): Unit = | ||
if delegateLogger.isErrorEnabled then | ||
delegateLogger.error(s"Error ${err.causeMsg}") | ||
end Slf4JLogger | ||
object Slf4JLogger: | ||
def logger(name: String) = Slf4JLogger(LoggerFactory.getLogger(name)) | ||
end Slf4JLogger |
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
Oops, something went wrong.