Skip to content

Commit

Permalink
Merge pull request #32 from hmrc/API-3828
Browse files Browse the repository at this point in the history
API-3828: Have the SetLastAccessedDate job actually run...
  • Loading branch information
lburgos authored Jun 20, 2019
2 parents b78e814 + b2a700b commit da8bcfc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import uk.gov.hmrc.play.config.ServicesConfig
import uk.gov.hmrc.thirdpartyapplication.connector._
import uk.gov.hmrc.thirdpartyapplication.controllers.{ApplicationControllerConfig, DocumentationConfig}
import uk.gov.hmrc.thirdpartyapplication.models.TrustedApplicationsConfig
import uk.gov.hmrc.thirdpartyapplication.scheduled.{JobConfig, RefreshSubscriptionsJobConfig, UpliftVerificationExpiryJobConfig}
import uk.gov.hmrc.thirdpartyapplication.scheduled.{JobConfig, RefreshSubscriptionsJobConfig, SetLastAccessedDateJobConfig, UpliftVerificationExpiryJobConfig}
import uk.gov.hmrc.thirdpartyapplication.services.CredentialConfig

import scala.concurrent.duration.{Duration, FiniteDuration}
Expand All @@ -39,6 +39,7 @@ class ConfigurationModule extends Module {
bind[DocumentationConfig].toProvider[DocumentationConfigProvider],
bind[RefreshSubscriptionsJobConfig].toProvider[RefreshSubscriptionsJobConfigProvider],
bind[UpliftVerificationExpiryJobConfig].toProvider[UpliftVerificationExpiryJobConfigProvider],
bind[SetLastAccessedDateJobConfig].toProvider[SetLastAccessDateJobConfigProvider],
bind[ApiDefinitionConfig].toProvider[ApiDefinitionConfigProvider],
bind[ApiSubscriptionFieldsConfig].toProvider[ApiSubscriptionFieldsConfigProvider],
bind[ApiStorageConfig].toProvider[ApiStorageConfigProvider],
Expand Down Expand Up @@ -106,6 +107,21 @@ class UpliftVerificationExpiryJobConfigProvider @Inject()(val runModeConfigurati
}
}

@Singleton
class SetLastAccessDateJobConfigProvider @Inject()(val runModeConfiguration: Configuration, environment: Environment)
extends Provider[SetLastAccessedDateJobConfig] with ServicesConfig {

override protected def mode = environment.mode

override def get() = {

val jobConfig = runModeConfiguration.underlying.as[Option[JobConfig]](s"$env.setLastAccessedDateJob")
.getOrElse(JobConfig(FiniteDuration(60, SECONDS), FiniteDuration(1, HOURS), enabled = true)) // scalastyle:off magic.number

SetLastAccessedDateJobConfig(jobConfig.initialDelay, jobConfig.interval, jobConfig.enabled)
}
}

@Singleton
class ApiDefinitionConfigProvider @Inject()(val runModeConfiguration: Configuration, environment: Environment)
extends Provider[ApiDefinitionConfig] with ServicesConfig {
Expand Down
13 changes: 11 additions & 2 deletions app/uk/gov/hmrc/thirdpartyapplication/config/Scheduler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ class Scheduler @Inject()(upliftVerificationExpiryJobConfig: UpliftVerificationE
upliftVerificationExpiryJob: UpliftVerificationExpiryJob,
refreshSubscriptionsJobConfig: RefreshSubscriptionsJobConfig,
refreshSubscriptionsScheduledJob: RefreshSubscriptionsScheduledJob,
setLastAccessedDateJobConfig: SetLastAccessedDateJobConfig,
setLastAccessedDateJob: SetLastAccessedDateJob,
app: Application) extends RunningOfScheduledJobs {

override val scheduledJobs = {
override val scheduledJobs: Seq[ExclusiveScheduledJob] = {

val upliftJob: Seq[ExclusiveScheduledJob] = if (upliftVerificationExpiryJobConfig.enabled) {
Seq(upliftVerificationExpiryJob)
Expand All @@ -48,7 +50,14 @@ class Scheduler @Inject()(upliftVerificationExpiryJobConfig: UpliftVerificationE
} else {
Seq.empty
}
upliftJob ++ refreshJob

val accessDateJob = if (setLastAccessedDateJobConfig.enabled) {
Seq(setLastAccessedDateJob)
} else {
Seq.empty
}

upliftJob ++ refreshJob ++ accessDateJob

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import play.modules.reactivemongo.ReactiveMongoComponent
import uk.gov.hmrc.lock.{LockKeeper, LockRepository}
import uk.gov.hmrc.thirdpartyapplication.repository.ApplicationRepository

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.FiniteDuration
import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.ExecutionContext.Implicits.global

class SetLastAccessedDateJob @Inject()(val lockKeeper: SetLastAccessedDateJobLockKeeper,
jobConfig: SetLastAccessedDateJobConfig,
Expand Down Expand Up @@ -62,4 +62,4 @@ class SetLastAccessedDateJobLockKeeper @Inject()(mongo: ReactiveMongoComponent)
override val forceLockReleaseAfter: Duration = Duration.standardMinutes(10) //scalastyle:ignore magic.number
}

case class SetLastAccessedDateJobConfig(initialDelay: FiniteDuration, interval: FiniteDuration, enabled: Boolean, validity: FiniteDuration)
case class SetLastAccessedDateJobConfig(initialDelay: FiniteDuration, interval: FiniteDuration, enabled: Boolean)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package unit.uk.gov.hmrc.thirdpartyapplication.scheduled

import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeUnit.{HOURS, SECONDS}

import common.uk.gov.hmrc.thirdpartyapplication.testutils.ApplicationStateUtil
Expand All @@ -31,9 +30,9 @@ import uk.gov.hmrc.play.test.UnitSpec
import uk.gov.hmrc.thirdpartyapplication.repository.ApplicationRepository
import uk.gov.hmrc.thirdpartyapplication.scheduled.{SetLastAccessedDateJob, SetLastAccessedDateJobConfig, SetLastAccessedDateJobLockKeeper}

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.FiniteDuration
import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.ExecutionContext.Implicits.global

class SetLastAccessedDateJobSpec extends UnitSpec with MockitoSugar with MongoSpecSupport with BeforeAndAfterAll with ApplicationStateUtil {

Expand Down Expand Up @@ -61,10 +60,9 @@ class SetLastAccessedDateJobSpec extends UnitSpec with MockitoSugar with MongoSp
else Future.successful(None)
}

val upliftVerificationValidity = FiniteDuration(expiryTimeInDays, TimeUnit.DAYS)
val initialDelay = FiniteDuration(60, SECONDS) // scalastyle:off magic.number
val interval = FiniteDuration(24, HOURS) // scalastyle:off magic.number
val config = SetLastAccessedDateJobConfig(initialDelay, interval, enabled = true, upliftVerificationValidity)
val config = SetLastAccessedDateJobConfig(initialDelay, interval, enabled = true)

val underTest = new SetLastAccessedDateJob(mockLockKeeper, config, mockApplicationRepository)
}
Expand Down

0 comments on commit da8bcfc

Please sign in to comment.