Files
huly-platform/services/notification/pod-events-processor/src/clientCache.ts
T
Artyom SavchenkoandGitHub dfe7d3d17c feat: Add ability to schedule notifications (#10789)
* feat: Add ability to schedule notifications

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Clean up

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Clean up

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Add docker file

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Rename pod

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Add debug logging

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Reminder fixes

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Fix reminders

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Support reminders for all events

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Clean up

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Support for project todo

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Fix mismatched dependency

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Use base event class

Signed-off-by: Artem Savchenko <armisav@gmail.com>

---------

Signed-off-by: Artem Savchenko <armisav@gmail.com>
2026-07-06 11:30:21 +05:00

73 lines
2.3 KiB
TypeScript

//
// Copyright © 2026 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
import { type PersonId, type WorkspaceUuid } from '@hcengineering/core'
import type { ClientBundle } from './client'
import config from './config'
interface CacheEntry {
value: ClientBundle
expiresAt: number
}
const clientCache = new Map<string, CacheEntry>()
const inFlightClientCreations = new Map<string, Promise<ClientBundle>>()
export function getCacheKey (workspaceUuid: WorkspaceUuid, socialId: PersonId | undefined, serviceTag: string): string {
return `${workspaceUuid}:${socialId ?? 'system'}:${serviceTag}`
}
export function getCachedClient (
workspaceUuid: WorkspaceUuid,
socialId: PersonId | undefined,
serviceTag: string
): ClientBundle | undefined {
const key = getCacheKey(workspaceUuid, socialId, serviceTag)
const entry = clientCache.get(key)
if (entry === undefined) return undefined
if (entry.expiresAt <= Date.now()) {
clientCache.delete(key)
return undefined
}
return entry.value
}
export function setCachedClient (
workspaceUuid: WorkspaceUuid,
socialId: PersonId | undefined,
serviceTag: string,
value: ClientBundle
): void {
const key = getCacheKey(workspaceUuid, socialId, serviceTag)
clientCache.set(key, { value, expiresAt: Date.now() + config.ClientCacheTtlMs })
}
export function getInFlightClientCreation (key: string): Promise<ClientBundle> | undefined {
return inFlightClientCreations.get(key)
}
export function setInFlightClientCreation (key: string, creation: Promise<ClientBundle>): void {
inFlightClientCreations.set(key, creation)
}
export function clearInFlightClientCreation (key: string): void {
inFlightClientCreations.delete(key)
}
export function clearClientCachesForTests (): void {
clientCache.clear()
inFlightClientCreations.clear()
}