akka-crontab-streams


License

License

Categories

Categories

Akka Container Microservices Reactive libraries
GroupId

GroupId

me.lightspeed7
ArtifactId

ArtifactId

akka-crontab-streams_2.12
Last Version

Last Version

0.3.3
Release Date

Release Date

Type

Type

jar
Description

Description

akka-crontab-streams
akka-crontab-streams
Project URL

Project URL

http://github.com/dbuschman7/akka-crontab
Project Organization

Project Organization

me.lightspeed7

Download akka-crontab-streams_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/me.lightspeed7/akka-crontab-streams_2.12/ -->
<dependency>
    <groupId>me.lightspeed7</groupId>
    <artifactId>akka-crontab-streams_2.12</artifactId>
    <version>0.3.3</version>
</dependency>
// https://jarcasting.com/artifacts/me.lightspeed7/akka-crontab-streams_2.12/
implementation 'me.lightspeed7:akka-crontab-streams_2.12:0.3.3'
// https://jarcasting.com/artifacts/me.lightspeed7/akka-crontab-streams_2.12/
implementation ("me.lightspeed7:akka-crontab-streams_2.12:0.3.3")
'me.lightspeed7:akka-crontab-streams_2.12:jar:0.3.3'
<dependency org="me.lightspeed7" name="akka-crontab-streams_2.12" rev="0.3.3">
  <artifact name="akka-crontab-streams_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='me.lightspeed7', module='akka-crontab-streams_2.12', version='0.3.3')
)
libraryDependencies += "me.lightspeed7" % "akka-crontab-streams_2.12" % "0.3.3"
[me.lightspeed7/akka-crontab-streams_2.12 "0.3.3"]

Dependencies

compile (6)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.7
me.lightspeed7 : akka-crontab_2.12 jar 0.3.3
org.scala-lang.modules : scala-parser-combinators_2.12 jar 1.1.2
com.typesafe.akka : akka-actor_2.12 jar 2.5.25
org.slf4j : slf4j-api jar 1.7.25
com.typesafe.akka : akka-stream_2.12 jar 2.5.25

test (4)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.0.8
com.typesafe.akka : akka-testkit_2.12 jar 2.5.25
org.slf4j : slf4j-simple jar 1.7.25
com.typesafe.akka : akka-stream-testkit_2.12 jar 2.5.25

Project Modules

There are no modules declared in this project.

akka-crontab

Bintray

Running crontabs with an Akka ActorSystem without a ton of dependencies

See (Wikipedia)[https://en.wikipedia.org/wiki/Cron]

Summary

  • Uses Java 8 Time API for data and time calculations
  • Slf4j for common logging support
  • Minimalized dependencies - KISS
  • Available for Scala 2.11, 2.12 and 2.13

Build setup

resolvers in ThisBuild += Resolver.jcenterRepo

plus

libraryDependencies ++= “me.lightspeed7” %% “akka-crontab” % “0.3.3”

or

libraryDependencies ++= “me.lightspeed7” %% “akka-crontab-streams” % “0.3.3”

Constructing Cron object

Cron object can be constructed from various helper methods and Raw construction

import me.lightspeed7.crontab.Crontab._

val daily = Crontab.daily
val hourly = Crontab.hourly 
val everyDayAt = Crontab.everyDayAt(12)

val everyHourOnTheHour = Cron(Fixed(0), Every, Every, Every, Every) 

Parsing using StringInterpolator

import me.lightspeed7.crontab._

val parsed1: Try[Cron] = cron"1 * * * *"
val parsed2: Try[Cron] = Crontab.apply("1 * * * *")

Scheduling - finding the next time from the cron to run

import me.lightspeed7.crontab._
import scala.concurrent.duration._
cron"".map { implicit cron =>
  val nextRunTime: Future[LocalDateTime] = Schedule.nextScheduledTime(LocalDateTime.now, 5 seconds)
  // ...
}

Running a Cron with Akka Actor

import me.lightspeed7.crontab._

class CronActor(cron: Cron) extends Actor {

  val scheduler = context.actorOf(Props(classOf[ScheduleActor], CronConfig(self, cron)))

  def receive: Actor.Receive = {
    case time: LocalDateTime =>
      // cron needs to run
    ...  
  }
}

Running a Cron as an Akka Stream Source

import me.lightspeed7.crontab._

val cron: Cron = ... 

val sink = Sink.foreach[LocalDateTime] { dt => println(s"Fired - $dt") }

val src: Source[LocalDateTime, NotUsed] = StreamSource.create(cron)
    
src.runWith(sink) // run your stream

Versions

Version
0.3.3
0.3.2