File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
bundle-monix-http4s-blaze/src/main/scala/com/avast/sst/bundle
bundle-zio-http4s-blaze/src/main/scala/com/avast/sst/bundle Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .avast .sst .bundle
2
+
3
+ import cats .effect .{ExitCode , Resource }
4
+ import monix .eval .{Task , TaskApp }
5
+ import org .slf4j .LoggerFactory
6
+
7
+ /** Extend this `trait` if you want to implement application using [[monix.eval.Task ]] effect data type.
8
+ *
9
+ * Implement method `program` with initialization and business logic of your application. It will be automatically run and cleaned up.
10
+ */
11
+ trait MonixResourceApp [A ] extends TaskApp {
12
+
13
+ private val logger = LoggerFactory .getLogger(this .getClass)
14
+
15
+ def program : Resource [Task , A ]
16
+
17
+ override def run (args : List [String ]): Task [ExitCode ] = {
18
+ program
19
+ .use(_ => Task .unit)
20
+ .redeem(
21
+ ex => {
22
+ logger.error(" Application initialization failed!" , ex)
23
+ ExitCode .Error
24
+ },
25
+ _ => ExitCode .Success
26
+ )
27
+ }
28
+
29
+ }
Original file line number Diff line number Diff line change
1
+ package com .avast .sst .bundle
2
+
3
+ import cats .effect .Resource
4
+ import org .slf4j .LoggerFactory
5
+ import zio .interop .catz ._
6
+ import zio .{Task , ZIO }
7
+
8
+ /** Extend this `trait` if you want to implement application using [[zio.ZIO ]] effect data type.
9
+ *
10
+ * Implement method `program` with initialization and business logic of your application. It will be automatically run and cleaned up.
11
+ */
12
+ trait ZioResourceApp [A ] extends CatsApp {
13
+
14
+ private val logger = LoggerFactory .getLogger(this .getClass)
15
+
16
+ def program : Resource [Task , A ]
17
+
18
+ override def run (args : List [String ]): ZIO [Environment , Nothing , Int ] = {
19
+ program
20
+ .use(_ => Task .unit)
21
+ .fold(
22
+ ex => {
23
+ logger.error(" Application initialization failed!" , ex)
24
+ 1
25
+ },
26
+ _ => 0
27
+ )
28
+ }
29
+
30
+ }
You can’t perform that action at this time.
0 commit comments