mirror of
https://github.com/ysoftdevs/odc-analyzer.git
synced 2026-04-20 23:51:30 +02:00
Enhanced locking
This commit is contained in:
@@ -8,12 +8,14 @@ import controllers.Statistics.LibDepStatistics
|
||||
import models.{EmailMessageId, ExportedVulnerability}
|
||||
import play.api.i18n.MessagesApi
|
||||
import play.api.libs.Crypto
|
||||
import play.api.mvc.Action
|
||||
import play.api.mvc.{RequestHeader, Action}
|
||||
import play.api.{Configuration, Logger}
|
||||
import services.{EmailExportService, IssueTrackerService, LibrariesService, VulnerabilityNotificationService}
|
||||
import views.html.DefaultRequest
|
||||
|
||||
import scala.concurrent.Future.{successful => Fut}
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import com.ysoft.concurrent.FutureLock._
|
||||
|
||||
class Notifications @Inject()(
|
||||
config: Configuration,
|
||||
@@ -90,13 +92,11 @@ class Notifications @Inject()(
|
||||
|
||||
def cron(key: String, purgeCache: Boolean) = Action.async{
|
||||
if(Crypto.constantTimeEquals(key, config.getString("yssdc.cronKey").get)){
|
||||
if(cronJobIsRunning.compareAndSet(/*expect = */false, /*update = */true)){
|
||||
// TODO: reduce the opportunity for not releasing the lock and make it clear it can't happen
|
||||
futureLock(cronJobIsRunning) {
|
||||
if (purgeCache) {
|
||||
projectReportsProvider.purgeCache(Map())
|
||||
}
|
||||
val (lastRefreshTime, resultsFuture) = projectReportsProvider.resultsForVersions(versions)
|
||||
(
|
||||
for {
|
||||
(successfulReports, failedReports) <- resultsFuture
|
||||
libraries <- librariesService.all
|
||||
@@ -111,10 +111,7 @@ class Notifications @Inject()(
|
||||
"\n\n" +
|
||||
missingEmails.mkString("\n") + "\n\n" + newMessageIds.mkString("\n") + updatedEmails.toString
|
||||
)
|
||||
).andThen{ case _ =>
|
||||
cronJobIsRunning.set(false)
|
||||
}
|
||||
}else{
|
||||
} whenLocked {
|
||||
Fut(ServiceUnavailable("A cron job seems to be running at this time"))
|
||||
}
|
||||
}else{
|
||||
|
||||
Reference in New Issue
Block a user