Skip to content

Commit

Permalink
Switch from LocalDateTime to Instant for measuring purposes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesname committed Nov 13, 2024
1 parent 68444ca commit 0f0f2b9
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
8 changes: 4 additions & 4 deletions modules/admin/app/actors/cleanup/CleanupRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import play.api.Configuration
import services.data.{DataService, EventForwarder}
import services.ingest.{Cleanup, ImportLogService, IngestService}

import java.time.LocalDateTime
import java.time.Instant
import java.util.concurrent.TimeUnit
import scala.concurrent.ExecutionContext
import scala.concurrent.duration.{Duration, FiniteDuration}
Expand Down Expand Up @@ -53,12 +53,12 @@ case class CleanupRunner(
// Start the initial harvest
case job: CleanupJob =>
val msgTo = sender()
context.become(running(job, msgTo, Status(), LocalDateTime.now()))
context.become(running(job, msgTo, Status(), Instant.now()))
logService.cleanup(job.repoId, job.snapshotId)
.pipeTo(self)
}

def running(job: CleanupJob, msgTo: ActorRef, status: Status, time: LocalDateTime): Receive = {
def running(job: CleanupJob, msgTo: ActorRef, status: Status, time: Instant): Receive = {
// Launch the relink task
case cleanup: Cleanup =>
msgTo ! cleanup
Expand Down Expand Up @@ -107,7 +107,7 @@ case class CleanupRunner(
// When there are no more items to delete, save the cleanup log and finish
case DeleteBatch(cleanup, todo, _) if todo.isEmpty =>
logService.saveCleanup(job.repoId, job.snapshotId, cleanup)
.map(_ => msgTo ! Done(FiniteDuration(java.time.Duration.between(time, LocalDateTime.now).toNanos, TimeUnit.NANOSECONDS)))
.map(_ => msgTo ! Done(FiniteDuration(java.time.Duration.between(time, Instant.now).toNanos, TimeUnit.NANOSECONDS)))

case m =>
msgTo ! s"Unexpected message: $m"
Expand Down
10 changes: 5 additions & 5 deletions modules/admin/app/actors/harvesting/OaiPmhHarvester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import models.{OaiPmhConfig, UserProfile}
import services.harvesting.{OaiPmhClient, OaiPmhError}
import services.storage.FileStorage

import java.time.{Duration, Instant, LocalDateTime}
import java.time.{Duration, Instant}
import scala.concurrent.ExecutionContext


Expand Down Expand Up @@ -66,7 +66,7 @@ case class OaiPmhHarvester (client: OaiPmhClient, storage: FileStorage)(
// Start the initial harvest
case job: OaiPmhHarvestJob =>
val msgTo = sender()
context.become(running(job, msgTo, 0, LocalDateTime.now()))
context.become(running(job, msgTo, 0, Instant.now()))
msgTo ! Starting
client.listIdentifiers(job.data.config, from = job.data.from)
.map { case (idents, next) =>
Expand All @@ -77,7 +77,7 @@ case class OaiPmhHarvester (client: OaiPmhClient, storage: FileStorage)(


// The harvest is running
def running(job: OaiPmhHarvestJob, msgTo: ActorRef, done: Int, start: LocalDateTime): Receive = {
def running(job: OaiPmhHarvestJob, msgTo: ActorRef, done: Int, start: Instant): Receive = {

// Harvest a new batch via a resumptionToken
case Next(token) =>
Expand Down Expand Up @@ -134,8 +134,8 @@ case class OaiPmhHarvester (client: OaiPmhClient, storage: FileStorage)(
log.error(s"Unexpected message: $m: ${m.getClass}")
}

private def time(from: LocalDateTime): Long =
Duration.between(from, LocalDateTime.now()).toMillis / 1000
private def time(from: Instant): Long =
Duration.between(from, Instant.now()).toMillis / 1000

private def fileName(prefix: String, id: String): String = prefix + id + ".xml"

Expand Down
10 changes: 5 additions & 5 deletions modules/admin/app/actors/harvesting/ResourceSyncHarvester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import models.{FileLink, ResourceSyncConfig, UserProfile}
import services.harvesting.ResourceSyncClient
import services.storage.FileStorage

import java.time.{Duration, LocalDateTime}
import java.time.{Duration, Instant}
import scala.concurrent.Future.{successful => immediate}
import scala.concurrent.{ExecutionContext, Future}

Expand Down Expand Up @@ -50,7 +50,7 @@ case class ResourceSyncHarvester (client: ResourceSyncClient, storage: FileStora
// Start the initial harvest
case job: ResourceSyncJob =>
val msgTo = sender()
context.become(running(job, msgTo, 0, 0, LocalDateTime.now()))
context.become(running(job, msgTo, 0, 0, Instant.now()))
msgTo ! Starting
client.list(job.data.config)
.map {list =>
Expand All @@ -62,7 +62,7 @@ case class ResourceSyncHarvester (client: ResourceSyncClient, storage: FileStora


// The harvest is running
def running(job: ResourceSyncJob, msgTo: ActorRef, done: Int, fresh: Int, start: LocalDateTime): Receive = {
def running(job: ResourceSyncJob, msgTo: ActorRef, done: Int, fresh: Int, start: Instant): Receive = {
// Harvest an individual item
case Fetch(item :: rest, count, fresh) =>
log.debug(s"Calling become with new total: $count")
Expand Down Expand Up @@ -122,6 +122,6 @@ case class ResourceSyncHarvester (client: ResourceSyncClient, storage: FileStora
}
}

private def time(from: LocalDateTime): Long =
Duration.between(from, LocalDateTime.now()).toMillis / 1000
private def time(from: Instant): Long =
Duration.between(from, Instant.now()).toMillis / 1000
}
10 changes: 5 additions & 5 deletions modules/admin/app/actors/harvesting/UrlSetHarvester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import play.api.http.HeaderNames
import play.api.libs.ws.{WSAuthScheme, WSClient}
import services.storage.FileStorage

import java.time.{Duration, LocalDateTime}
import java.time.{Duration, Instant}
import scala.concurrent.Future.{successful => immediate}
import scala.concurrent.{ExecutionContext, Future}

Expand Down Expand Up @@ -51,15 +51,15 @@ case class UrlSetHarvester (client: WSClient, storage: FileStorage)(
// Start the initial harvest
case job: UrlSetHarvesterJob =>
val msgTo = sender()
context.become(running(job, msgTo, 0, 0, LocalDateTime.now()))
context.become(running(job, msgTo, 0, 0, Instant.now()))
msgTo ! Starting
msgTo ! ToDo(job.data.config.urlMap.size)
self ! Fetch(job.data.config.urls.toList, 0, 0)
}


// The harvest is running
def running(job: UrlSetHarvesterJob, msgTo: ActorRef, done: Int, fresh: Int, start: LocalDateTime): Receive = {
def running(job: UrlSetHarvesterJob, msgTo: ActorRef, done: Int, fresh: Int, start: Instant): Receive = {
// Harvest an individual item
case Fetch(item :: rest, count, fresh) =>
log.debug(s"Calling become with new total: $count")
Expand Down Expand Up @@ -134,6 +134,6 @@ case class UrlSetHarvester (client: WSClient, storage: FileStorage)(
}
}

private def time(from: LocalDateTime): Long =
Duration.between(from, LocalDateTime.now()).toMillis / 1000
private def time(from: Instant): Long =
Duration.between(from, Instant.now()).toMillis / 1000
}
8 changes: 4 additions & 4 deletions modules/admin/app/actors/ingest/DataImporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import models._
import services.ingest.IngestService.{IngestData, IngestJob}
import services.ingest._

import java.time.LocalDateTime
import java.time.Instant
import scala.concurrent.{ExecutionContext, Future}


Expand All @@ -17,7 +17,7 @@ object DataImporter {
case object Start extends State
case object ImportBatch extends State
case class SaveLog(log: ImportLog) extends State
case class Done(start: LocalDateTime) extends State
case class Done(start: Instant) extends State
case class Message(msg: String) extends State
case class UnexpectedError(throwable: Throwable) extends State
}
Expand Down Expand Up @@ -48,11 +48,11 @@ case class DataImporter(

// Importer initializing...
val msgForwarder = context.actorOf(Props(Forwarder(msgTo)))
context.become(running(msgTo, job.data.head, job.data.tail, msgForwarder, LocalDateTime.now()))
context.become(running(msgTo, job.data.head, job.data.tail, msgForwarder, Instant.now()))
self ! ImportBatch
}

def running(msgTo: ActorRef, data: IngestData, todo: Seq[IngestData], forwarder: ActorRef, start: LocalDateTime): Receive = {
def running(msgTo: ActorRef, data: IngestData, todo: Seq[IngestData], forwarder: ActorRef, start: Instant): Receive = {
case ImportBatch =>
context.become(running(msgTo, data, todo, forwarder, start))

Expand Down
10 changes: 5 additions & 5 deletions modules/admin/app/actors/transformation/XmlConverter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import services.storage.{FileMeta, FileStorage}
import services.transformation.XmlTransformer

import java.net.URI
import java.time.{Duration, LocalDateTime}
import java.time.{Duration, Instant}
import scala.concurrent.Future.{successful => immediate}
import scala.concurrent.duration.DurationInt
import scala.concurrent.{ExecutionContext, Future}
Expand Down Expand Up @@ -49,14 +49,14 @@ case class XmlConverter (job: XmlConvertJob, transformer: XmlTransformer, storag
// Start the initial harvest
case Initial =>
val msgTo = sender()
context.become(counting(msgTo, LocalDateTime.now()))
context.become(counting(msgTo, Instant.now()))
msgTo ! Starting
msgTo ! Counting
self ! Counting
}

// We're counting the full set of files to convert
def counting(msgTo: ActorRef, start: LocalDateTime): Receive = {
def counting(msgTo: ActorRef, start: Instant): Receive = {
// Count files in the given prefix...
case Counting =>
if (job.data.only.nonEmpty) self ! Counted(1)
Expand All @@ -73,7 +73,7 @@ case class XmlConverter (job: XmlConvertJob, transformer: XmlTransformer, storag


// The convert job is running
def running(msgTo: ActorRef, done: Int, fresh: Int, total: Int, start: LocalDateTime): Receive = {
def running(msgTo: ActorRef, done: Int, fresh: Int, total: Int, start: Instant): Receive = {

// Fetch a list of files from the storage API
case FetchFiles(after) =>
Expand Down Expand Up @@ -191,7 +191,7 @@ case class XmlConverter (job: XmlConvertJob, transformer: XmlTransformer, storag
}
}

private def time(from: LocalDateTime): Long = Duration.between(from, LocalDateTime.now()).toMillis / 1000
private def time(from: Instant): Long = Duration.between(from, Instant.now()).toMillis / 1000

private def basename(key: String): String = key.replace(job.data.inPrefix, "")
}
4 changes: 2 additions & 2 deletions test/services/cypher/MockCypherQueryService.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package services.cypher

import java.time.LocalDateTime
import java.time.Instant

import models.CypherQuery
import services.data.ItemNotFound
Expand All @@ -17,7 +17,7 @@ case class MockCypherQueryService(buffer: collection.mutable.HashMap[Int, Cypher

override def update(id: String, cypherQuery: CypherQuery): Future[String] = {
buffer += id.toInt -> cypherQuery
immediate(LocalDateTime.now.toString)
immediate(Instant.now.toString)
}

override def delete(id: String): Future[Boolean] = {
Expand Down

0 comments on commit 0f0f2b9

Please sign in to comment.