Skip to content

Commit

Permalink
Use seconds instead of millis (#28)
Browse files Browse the repository at this point in the history
* Use seconds instead of millis
  • Loading branch information
nryanov committed May 12, 2021
1 parent 184e2f6 commit b5fcb4a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ name: genkai CI

on:
pull_request:
branches:
- master
branches: ['*']
push:
branches:
- master
branches: ['*']

jobs:
scalafmt:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ object AerospikeStrategy {
private val argsPart = List(
Value.get(underlying.tokens),
Value.get(underlying.refillAmount),
Value.get(underlying.refillDelay.toMillis)
Value.get(underlying.refillDelay.toSeconds)
)

override val luaScript: String = LuaScript.tokenBucket
Expand All @@ -103,10 +103,10 @@ object AerospikeStrategy {
new AKey(namespace, setName, Key[A].convert(value))

override def permissionsArgs(instant: Instant): List[Value] =
Value.get(instant.toEpochMilli) :: argsPart
Value.get(instant.getEpochSecond) :: argsPart

override def acquireArgs(instant: Instant, cost: Long): List[Value] =
Value.get(instant.toEpochMilli) :: Value.get(cost) :: argsPart
Value.get(instant.getEpochSecond) :: Value.get(cost) :: argsPart

override def isAllowed(value: Long): Boolean = value != 0

Expand Down Expand Up @@ -141,7 +141,7 @@ object AerospikeStrategy {
override def permissionsArgs(instant: Instant): List[Value] = permissionArgsPart

override def acquireArgs(instant: Instant, cost: Long): List[Value] =
Value.get(instant.toEpochMilli) :: Value.get(cost) :: acquireArgsPart
Value.get(instant.getEpochSecond) :: Value.get(cost) :: acquireArgsPart

override def isAllowed(value: Long): Boolean = value != 0

Expand Down Expand Up @@ -181,7 +181,7 @@ object AerospikeStrategy {
override def permissionsArgs(instant: Instant): List[Value] = argsPart

override def acquireArgs(instant: Instant, cost: Long): List[Value] =
Value.get(instant.toEpochMilli) :: Value.get(cost) :: argsPart
Value.get(instant.getEpochSecond) :: Value.get(cost) :: argsPart

override def isAllowed(value: Long): Boolean = value != 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object RedisStrategy {
private val argsPart = List(
underlying.tokens.toString,
underlying.refillAmount.toString,
underlying.refillDelay.toMillis.toString
underlying.refillDelay.toSeconds.toString
)

override val acquireLuaScript: String = LuaScript.tokenBucketAcquire
Expand All @@ -80,10 +80,10 @@ object RedisStrategy {
List(s"token_bucket:${Key[A].convert(value)}")

override def permissionsArgs(instant: Instant): List[String] =
instant.toEpochMilli.toString :: argsPart
instant.getEpochSecond.toString :: argsPart

override def acquireArgs(instant: Instant, cost: Long): List[String] =
instant.toEpochMilli.toString :: cost.toString :: argsPart
instant.getEpochSecond.toString :: cost.toString :: argsPart

override def isAllowed(value: Long): Boolean = value != 0

Expand All @@ -105,7 +105,7 @@ object RedisStrategy {

override def keys[A: Key](value: A, instant: Instant): List[String] = {

val ts = instant.truncatedTo(underlying.window.unit).toEpochMilli
val ts = instant.truncatedTo(underlying.window.unit).getEpochSecond
List(s"fixed_window:${Key[A].convert(value)}:$ts")
}

Expand Down Expand Up @@ -141,10 +141,10 @@ object RedisStrategy {
)

override def permissionsArgs(instant: Instant): List[String] =
instant.toEpochMilli.toString :: permissionArgsPart
instant.getEpochSecond.toString :: permissionArgsPart

override def acquireArgs(instant: Instant, cost: Long): List[String] =
instant.toEpochMilli.toString :: cost.toString :: acquireArgsPart
instant.getEpochSecond.toString :: cost.toString :: acquireArgsPart

override def isAllowed(value: Long): Boolean = value != 0

Expand Down

0 comments on commit b5fcb4a

Please sign in to comment.