Skip to content

Commit

Permalink
Merge pull request #164 from eikek/remove-fs2-module
Browse files Browse the repository at this point in the history
Remove fs2 module
  • Loading branch information
eikek authored Aug 20, 2021
2 parents 03185b9 + 4e8382a commit 220190d
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 266 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [ 'adopt@1.8', 'adopt@1.11', 'openjdk@1.11', 'zulu@1.16' ]
java: [ 8, 11, 17 ]
steps:
- uses: actions/checkout@v2.3.4
with:
Expand Down
3 changes: 0 additions & 3 deletions .scala-steward.conf

This file was deleted.

100 changes: 26 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ compared to systemd:
```sbt
libraryDependencies += "com.github.eikek" %% "calev-core" % "0.5.4"
```
- The *fs2* module contains utilities to work with
[FS2](https://github.com/functional-streams-for-scala/fs2) streams.
These were taken, thankfully and slightly modified to exchange cron expressions
for calendar events, from the
[fs2-cron](https://github.com/fthomas/fs2-cron) library. It is also published
for ScalaJS. With sbt, use
```sbt
libraryDependencies += "com.github.eikek" %% "calev-fs2" % "0.5.4"
```
- The *doobie* module contains `Meta`, `Read` and `Write` instances
for `CalEvent` to use with
[doobie](https://github.com/tpolecat/doobie).
Expand All @@ -85,6 +76,10 @@ compared to systemd:
libraryDependencies += "com.github.eikek" %% "calev-akka" % "0.5.4"
```

Note that the fs2 module has been removed. The functionality is now
available for fs2 3.x from the
[fs2-cron](https://github.com/fthomas/fs2-cron) library. If calev-fs2
is required for fs2 2.x, calev version 0.5.4 can be used.

## Examples

Expand Down Expand Up @@ -167,16 +162,16 @@ import java.time._
ce.asString
// res4: String = "*-*-* 00/2:00:00"
val now = LocalDateTime.now
// now: LocalDateTime = 2021-06-30T00:21:12.170
// now: LocalDateTime = 2021-08-20T18:50:58.888
ce.nextElapse(now)
// res5: Option[LocalDateTime] = Some(value = 2021-06-30T02:00)
// res5: Option[LocalDateTime] = Some(value = 2021-08-20T20:00)
ce.nextElapses(now, 5)
// res6: List[LocalDateTime] = List(
// 2021-06-30T02:00,
// 2021-06-30T04:00,
// 2021-06-30T06:00,
// 2021-06-30T08:00,
// 2021-06-30T10:00
// 2021-08-20T20:00,
// 2021-08-20T22:00,
// 2021-08-21T00:00,
// 2021-08-21T02:00,
// 2021-08-21T04:00
// )
```

Expand All @@ -188,54 +183,6 @@ CalEvent.unsafe("1900-01-* 12,14:0:0").nextElapse(LocalDateTime.now)
```


### FS2

The fs2 utilities allow to schedule things based on calendar events.
This is the same as [fs2-cron](https://github.com/fthomas/fs2-cron)
provides, only adopted to use calendar events instead of cron
expressions. The example is also from there.

**Note:** `calev-fs2` is still build against fs2 2.x. This module will
be removed in the future, because the
[fs2-cron](https://github.com/fthomas/fs2-cron) project now provides
this via its `fs2-cron-calev` module, which is built against fs2 3
already.

```scala
import cats.effect.{IO, Timer}
import fs2.Stream
import com.github.eikek.fs2calev._
import java.time.LocalTime
import scala.concurrent.ExecutionContext

implicit val timer: Timer[IO] = IO.timer(ExecutionContext.global)
// timer: Timer[IO] = cats.effect.internals.IOTimer@4406d447

val printTime = IO(println(LocalTime.now))
// printTime: IO[Unit] = Delay(thunk = <function0>)

val event = CalEvent.unsafe("*-*-* *:*:0/2")
// event: CalEvent = CalEvent(
// weekday = All,
// date = DateEvent(year = All, month = All, day = All),
// time = TimeEvent(
// hour = All,
// minute = All,
// seconds = List(values = Vector(Single(value = 0, rep = Some(value = 2))))
// ),
// zone = None
// )

val task = CalevFs2.awakeEvery[IO](event).evalMap(_ => printTime)
// task: Stream[IO[x], Unit] = Stream(..)

task.take(3).compile.drain.unsafeRunSync()
// 00:21:14.021
// 00:21:16
// 00:21:18.001
```


### Doobie

When using doobie, this module contains instances to write and read
Expand Down Expand Up @@ -270,8 +217,8 @@ val insert =
// acquire = Suspend(
// a = PrepareStatement(a = "INSERT INTO mytable (event) VALUES (?)")
// ),
// use = doobie.hi.connection$$$Lambda$11625/2046523540@5c2fb3a6,
// release = cats.effect.Bracket$$Lambda$11627/540350284@8c0f281
// use = doobie.hi.connection$$$Lambda$38918/2009939920@2835fff2,
// release = cats.effect.Bracket$$Lambda$38920/1634253453@461bcb5d
// )
// )

Expand All @@ -282,8 +229,8 @@ val select =
// acquire = Suspend(
// a = PrepareStatement(a = "SELECT event FROM mytable WHERE id = 1")
// ),
// use = doobie.hi.connection$$$Lambda$11625/2046523540@1c03aa81,
// release = cats.effect.Bracket$$Lambda$11627/540350284@430a5324
// use = doobie.hi.connection$$$Lambda$38918/2009939920@3277d9fb,
// release = cats.effect.Bracket$$Lambda$38920/1634253453@1e9b8fb8
// )
// )
```
Expand Down Expand Up @@ -357,6 +304,8 @@ val read = for {
// )
// )
```


### Jackson

Add `CalevModule` to use calendar event expressions in json:
Expand All @@ -371,7 +320,7 @@ val jackson = JsonMapper
.builder()
.addModule(new CalevModule())
.build()
// jackson: JsonMapper = com.fasterxml.jackson.databind.json.JsonMapper@62197a60
// jackson: JsonMapper = com.fasterxml.jackson.databind.json.JsonMapper@10f58b2

val myEvent = CalEvent.unsafe("Mon *-*-* 05:00/10:00")
// myEvent: CalEvent = CalEvent(
Expand Down Expand Up @@ -399,6 +348,8 @@ val eventDeserialized = jackson.readValue(eventSerialized, new TypeReference[Cal
// zone = None
// )
```


### Akka

#### Akka Timers
Expand Down Expand Up @@ -437,7 +388,7 @@ CalevBehaviors.withCalevTimers[Message]() { scheduler =>
same
}
}
// res9: Behavior[Message] = Deferred(TimerSchedulerImpl.scala:29)
// res8: Behavior[Message] = Deferred(TimerSchedulerImpl.scala:29)
```

Use ```CalevBehaviors.withCalendarEvent``` to schedule messages according
Expand All @@ -457,8 +408,9 @@ CalevBehaviors.withCalendarEvent(calEvent)(
same
}
)
// res10: Behavior[Message] = Deferred(InterceptorImpl.scala:29-30)
// res9: Behavior[Message] = Deferred(InterceptorImpl.scala:29-30)
```

#### Testing

See [CalevBehaviorsTest](https://github.com/eikek/calev/blob/master/modules/akka/src/test/scala/com/github/eikek/calev/akka/dsl/CalevBehaviorsTest.scala)
Expand Down Expand Up @@ -489,8 +441,8 @@ calevScheduler().scheduleOnceWithCalendarEvent(calEvent, () => {
s"Called at: ${LocalTime.now}"
)
})
// res11: Option[<none>.<root>.akka.actor.Cancellable] = Some(
// value = akka.actor.LightArrayRevolverScheduler$TaskHolder@48d6430
// res10: Option[<none>.<root>.akka.actor.Cancellable] = Some(
// value = akka.actor.LightArrayRevolverScheduler$TaskHolder@2deff253
// )
system.terminate()
```
```
19 changes: 1 addition & 18 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,6 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
lazy val coreJVM = core.jvm
lazy val coreJS = core.js

lazy val fs2 = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.in(file("modules/fs2"))
.settings(sharedSettings)
.settings(testSettings)
.settings(scalafixSettings)
.settings(
name := "calev-fs2",
libraryDependencies ++=
Dependencies.fs2
)
.dependsOn(core)
lazy val fs2JVM = fs2.jvm
lazy val fs2JS = fs2.js

lazy val doobieJVM = project
.in(file("modules/doobie"))
.settings(sharedSettings)
Expand Down Expand Up @@ -226,7 +211,7 @@ lazy val readme = project
()
}
)
.dependsOn(coreJVM, fs2JVM, doobieJVM, circeJVM, jacksonJVM, akkaJVM)
.dependsOn(coreJVM, doobieJVM, circeJVM, jacksonJVM, akkaJVM)

val root = project
.in(file("."))
Expand All @@ -239,8 +224,6 @@ val root = project
.aggregate(
coreJVM,
coreJS,
fs2JVM,
fs2JS,
doobieJVM,
circeJVM,
circeJS,
Expand Down
52 changes: 10 additions & 42 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ compared to systemd:
```sbt
libraryDependencies += "com.github.eikek" %% "calev-core" % "@VERSION@"
```
- The *fs2* module contains utilities to work with
[FS2](https://github.com/functional-streams-for-scala/fs2) streams.
These were taken, thankfully and slightly modified to exchange cron expressions
for calendar events, from the
[fs2-cron](https://github.com/fthomas/fs2-cron) library. It is also published
for ScalaJS. With sbt, use
```sbt
libraryDependencies += "com.github.eikek" %% "calev-fs2" % "@VERSION@"
```
- The *doobie* module contains `Meta`, `Read` and `Write` instances
for `CalEvent` to use with
[doobie](https://github.com/tpolecat/doobie).
Expand All @@ -85,6 +76,10 @@ compared to systemd:
libraryDependencies += "com.github.eikek" %% "calev-akka" % "@VERSION@"
```

Note that the fs2 module has been removed. The functionality is now
available for fs2 3.x from the
[fs2-cron](https://github.com/fthomas/fs2-cron) library. If calev-fs2
is required for fs2 2.x, calev version 0.5.4 can be used.

## Examples

Expand Down Expand Up @@ -134,38 +129,6 @@ CalEvent.unsafe("1900-01-* 12,14:0:0").nextElapse(LocalDateTime.now)
```


### FS2

The fs2 utilities allow to schedule things based on calendar events.
This is the same as [fs2-cron](https://github.com/fthomas/fs2-cron)
provides, only adopted to use calendar events instead of cron
expressions. The example is also from there.

**Note:** `calev-fs2` is still build against fs2 2.x. This module will
be removed in the future, because the
[fs2-cron](https://github.com/fthomas/fs2-cron) project now provides
this via its `fs2-cron-calev` module, which is built against fs2 3
already.

```scala mdoc
import cats.effect.{IO, Timer}
import fs2.Stream
import com.github.eikek.fs2calev._
import java.time.LocalTime
import scala.concurrent.ExecutionContext

implicit val timer: Timer[IO] = IO.timer(ExecutionContext.global)

val printTime = IO(println(LocalTime.now))

val event = CalEvent.unsafe("*-*-* *:*:0/2")

val task = CalevFs2.awakeEvery[IO](event).evalMap(_ => printTime)

task.take(3).compile.drain.unsafeRunSync()
```


### Doobie

When using doobie, this module contains instances to write and read
Expand Down Expand Up @@ -214,6 +177,8 @@ val read = for {
value <- parsed.as[Meeting]
} yield value
```


### Jackson

Add `CalevModule` to use calendar event expressions in json:
Expand All @@ -234,6 +199,8 @@ val myEvent = CalEvent.unsafe("Mon *-*-* 05:00/10:00")
val eventSerialized = jackson.writeValueAsString(myEvent)
val eventDeserialized = jackson.readValue(eventSerialized, new TypeReference[CalEvent] {})
```


### Akka

#### Akka Timers
Expand Down Expand Up @@ -292,6 +259,7 @@ CalevBehaviors.withCalendarEvent(calEvent)(
}
)
```

#### Testing

See [CalevBehaviorsTest](https://github.com/eikek/calev/blob/master/modules/akka/src/test/scala/com/github/eikek/calev/akka/dsl/CalevBehaviorsTest.scala)
Expand Down Expand Up @@ -322,4 +290,4 @@ calevScheduler().scheduleOnceWithCalendarEvent(calEvent, () => {
)
})
system.terminate()
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ import java.time.LocalTime
import java.time.ZonedDateTime
import java.time.temporal.ChronoField

import scala.concurrent.ExecutionContext

import cats.effect._
import com.github.eikek.calev.Dsl._
import munit._

class CalEventTest extends FunSuite {

implicit val CS: ContextShift[IO] = IO.contextShift(ExecutionContext.global)
val blocker = Blocker.liftExecutionContext(ExecutionContext.global)

test("contains") {
val ce = CalEvent(Mon ~ Tue, DateEvent.All, time(0.c, 10.c ++ 20.c, 0.c))
assert(ce.contains(zdt(2015, 10, 12, 0, 10, 0)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,19 @@ case class TestDataSet(event: CalEvent, ref: ZonedDateTime, expect: List[ZonedDa
object TestDataSet {
type EA[B] = Either[Throwable, B]

def readResource[F[_]: Sync: ContextShift](
name: String,
blocker: Blocker
): Stream[F, EA[TestDataSet]] =
def readResource[F[_]: Sync](name: String): Stream[F, EA[TestDataSet]] =
Option(getClass.getResource(name)) match {
case Some(url) =>
read[F](url, blocker)
read[F](url)

case None =>
sys.error(s"Resource not found: $name")
}

def read[F[_]: Sync: ContextShift](
url: URL,
blocker: Blocker
): Stream[F, EA[TestDataSet]] =
def read[F[_]: Sync](url: URL): Stream[F, EA[TestDataSet]] =
fs2.io
.readInputStream(Sync[F].delay(url.openStream), 8192, blocker)
.through(fs2.text.utf8Decode)
.readInputStream(Sync[F].delay(url.openStream), 8192)
.through(fs2.text.utf8.decode)
.through(fs2.text.lines)
.filter(l => !l.trim.startsWith("#"))
.split(_.trim.isEmpty)
Expand Down
Loading

0 comments on commit 220190d

Please sign in to comment.