Files
directus/packages/utils/node/process-id.ts
Rijk van Zanten b0f5baa394 Add @directus/memory package (#20514)
* Add analytics table

* Setup memory package boilerplate

* Bootstrap library

* [WIP] setup serialize/deserialize for data

* Finish compress/serialize utils

* Add get/set for local

* Add increments method

* Add delete + comments

* Add pub/sub methods

* Remove erroneous files

* Add has, setMax

* Restructure to 3 subclasses

* WIP add Redis cache

* Add set-max

* Add cacheMulti

* Add tests for redis cache

* Don't compress small values

* Only decompress values that are compressed

* Add test for arr-to-buf

* Add tests for multi-stage cache

* Add test for create

* Finish redis based messenger bus

* Add redis bus to createBus

* Resolve lock file conflict

* Align dev deps versions

* Format files

* Update packages/memory/package.json

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>

* It's okay, ESLint

* Add local rate limiter

* Add redis limiter

* Add simple readme

* Add changeset

* 'key value' -> 'key-value'

* Sort package.json

* Remove leftovers

* Move timer calls to corresponding test

* Add KV asbraction based on previous "cache"

* Update cache to use kv

* Add more specific console logs

* Only define setMax if not exists

* Run formatter

* Use parseJSON util

* Fix typo in class docs

* Install directus/utils

* Default to Map if LRU config isn't set

* Ignore errors thrown in handlers

* Create process-id util

* Use pubsub in multi-stage handler

* WIP Update tests

* Update package lock

* Fix formatting errors

* Fix timestamp in test

* Uno mas

* Fix mock order

---------

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
2023-12-13 11:29:22 -05:00

20 lines
511 B
TypeScript

import { createHash } from 'node:crypto';
import { hostname } from 'node:os';
export const _cache: { id: string | undefined } = { id: undefined };
/**
* Return a unique hash for the current process on the current machine. Will be different after a
* restart
*/
export const processId = () => {
if (_cache.id) return _cache.id;
const parts = [hostname(), process.pid, new Date().getTime()];
const hash = createHash('md5').update(parts.join(''));
_cache.id = hash.digest('hex');
return _cache.id;
};