fs2-cron


License

License

GroupId

GroupId

eu.timepit
ArtifactId

ArtifactId

fs2-cron-core_2.11
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

fs2-cron
fs2-cron
Project URL

Project URL

https://github.com/fthomas/fs2-cron
Project Organization

Project Organization

eu.timepit
Source Code Management

Source Code Management

https://github.com/fthomas/fs2-cron

Download fs2-cron-core_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/eu.timepit/fs2-cron-core_2.11/ -->
<dependency>
    <groupId>eu.timepit</groupId>
    <artifactId>fs2-cron-core_2.11</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/eu.timepit/fs2-cron-core_2.11/
implementation 'eu.timepit:fs2-cron-core_2.11:0.1.0'
// https://jarcasting.com/artifacts/eu.timepit/fs2-cron-core_2.11/
implementation ("eu.timepit:fs2-cron-core_2.11:0.1.0")
'eu.timepit:fs2-cron-core_2.11:jar:0.1.0'
<dependency org="eu.timepit" name="fs2-cron-core_2.11" rev="0.1.0">
  <artifact name="fs2-cron-core_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='eu.timepit', module='fs2-cron-core_2.11', version='0.1.0')
)
libraryDependencies += "eu.timepit" % "fs2-cron-core_2.11" % "0.1.0"
[eu.timepit/fs2-cron-core_2.11 "0.1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
com.github.alonsodomin.cron4s : cron4s-core_2.11 jar 0.5.0
co.fs2 : fs2-core_2.11 jar 1.0.3

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.11 jar 3.0.5

Project Modules

There are no modules declared in this project.

fs2-cron

Build Status codecov Join the chat at https://gitter.im/fthomas/fs2-cron Scaladex Scaladoc

fs2-cron is a microlibrary that provides FS2 streams based on Cron4s cron expressions.

Examples

import cats.effect.{IO, Timer}
import cron4s.Cron
import eu.timepit.fs2cron.awakeEveryCron
import fs2.Stream
import java.time.LocalTime
import scala.concurrent.ExecutionContext

implicit val timer: Timer[IO] = IO.timer(ExecutionContext.global)
val evenSeconds = Cron.unsafeParse("*/2 * * ? * *")
// evenSeconds: cron4s.CronExpr = */2 * * ? * *

val printTime = Stream.eval(IO(println(LocalTime.now)))
// printTime: fs2.Stream[cats.effect.IO,Unit] = Stream(..)

val scheduled = awakeEveryCron[IO](evenSeconds) >> printTime
// scheduled: fs2.Stream[[x]cats.effect.IO[x],Unit] = Stream(..)

scheduled.take(3).compile.drain.unsafeRunSync
// 05:44:52.290
// 05:44:54.006
// 05:44:56.005
import cats.effect.ContextShift
import eu.timepit.fs2cron.schedule

implicit val ctxShift: ContextShift[IO] = IO.contextShift(ExecutionContext.global)
val everyFiveSeconds = Cron.unsafeParse("*/5 * * ? * *")
// everyFiveSeconds: cron4s.CronExpr = */5 * * ? * *

val scheduledTasks = schedule(List(
  evenSeconds      -> Stream.eval(IO(println(LocalTime.now.toString + " task 1"))),
  everyFiveSeconds -> Stream.eval(IO(println(LocalTime.now.toString + " task 2")))
))
// scheduledTasks: fs2.Stream[[+A]cats.effect.IO[A],Unit] = Stream(..)

scheduledTasks.take(9).compile.drain.unsafeRunSync
// 05:44:58.003 task 1
// 05:45:00.007 task 1
// 05:45:00.007 task 2
// 05:45:02.006 task 1
// 05:45:04.007 task 1
// 05:45:05.006 task 2
// 05:45:06.007 task 1
// 05:45:08.005 task 1
// 05:45:10.004 task 2
// 05:45:10.004 task 1

Using fs2-cron

The latest version of the library is available for Scala 2.12 and 2.13.

If you're using sbt, add the following to your build:

libraryDependencies ++= Seq(
  "eu.timepit" %% "fs2-cron-core" % "0.2.2"
)

License

fs2-cron is licensed under the Apache License, Version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 and also in the LICENSE file.

Versions

Version
0.1.0
0.0.12