Skip to content

Commit

Permalink
Make calculations easier to read
Browse files Browse the repository at this point in the history
Refs #1834
  • Loading branch information
thewilkybarkid committed Dec 20, 2024
1 parent b392b1f commit f63764a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/ExpressServer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FetchHttpClient } from '@effect/platform'
import KeyvRedis from '@keyv/redis'
import { Effect, Redacted } from 'effect'
import { Duration, Effect, Redacted } from 'effect'
import Keyv from 'keyv'
import { app } from './app.js'
import { DeprecatedEnvVars, DeprecatedLoggerEnv, DeprecatedSleepEnv, ExpressConfig, SessionSecret } from './Context.js'
Expand Down Expand Up @@ -102,7 +102,7 @@ export const ExpressConfigLive = Effect.gen(function* () {
emitErrors: false,
namespace: 'sessions',
store: createKeyvStore(),
ttl: 1000 * 60 * 60 * 24 * 30,
ttl: Duration.toMillis('30 days'),
}),
slackOauth: {
authorizeUrl: new URL('https://slack.com/oauth/v2/authorize'),
Expand Down
7 changes: 5 additions & 2 deletions src/Redis.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Config, Context, Effect, flow, Inspectable, Layer, pipe, Redacted, Runtime } from 'effect'
import { Config, Context, Duration, Effect, flow, Inspectable, Layer, pipe, Redacted, Runtime } from 'effect'
import { Redis as IoRedis } from 'ioredis'

const makeRedis = (url: Redacted.Redacted<URL>) =>
Effect.gen(function* () {
const runtime = yield* Effect.runtime()
const redis = new IoRedis(Redacted.value(url).href, { commandTimeout: 2 * 1000, enableAutoPipelining: true })
const redis = new IoRedis(Redacted.value(url).href, {
commandTimeout: Duration.toMillis('2 seconds'),
enableAutoPipelining: true,
})

const runSync = Runtime.runSync(runtime)

Expand Down
4 changes: 2 additions & 2 deletions src/WebApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Path,
} from '@effect/platform'
import cookieSignature from 'cookie-signature'
import { Cause, Config, Effect, flow, Layer, Option, pipe, Redacted, Schema } from 'effect'
import { Cause, Config, Duration, Effect, flow, Layer, Option, pipe, Redacted, Schema } from 'effect'
import { StatusCodes } from 'http-status-codes'
import { Express, ExpressConfig, FlashMessage, Locale, SessionSecret } from './Context.js'
import { ExpressHttpApp } from './ExpressHttpApp.js'
Expand Down Expand Up @@ -61,7 +61,7 @@ const serveStaticFiles = HttpMiddleware.make(app =>
return yield* HttpServerResponse.setHeader(
response,
'Cache-Control',
`public, max-age=${60 * 60 * 24 * 365}, immutable`,
`public, max-age=${Duration.toSeconds('365 days')}, immutable`,
)
}),
)
Expand Down
3 changes: 2 additions & 1 deletion src/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Duration } from 'effect'
import type * as F from 'fetch-fp-ts'
import { constVoid } from 'fp-ts/lib/function.js'
import type { Json } from 'fp-ts/lib/Json.js'
Expand Down Expand Up @@ -32,7 +33,7 @@ export function revalidateIfStale<E extends F.FetchEnv & SleepEnv>(): (env: E) =
openRequests.add(url)

void env
.sleep(Math.min(200 * openRequests.size, 30_000))()
.sleep(Duration.toMillis(Duration.min(Duration.times('0.2 seconds', openRequests.size), '30 seconds')))()
.then(() => env.fetch(url, { ...init, cache: 'no-cache' }))
.then(response => response.text())
.catch(constVoid)
Expand Down

0 comments on commit f63764a

Please sign in to comment.