-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logs): timeout old operations (#2220)
## Describe your changes Fixes NAN-1036 Since we have only 15days retention and syncs are unlimited it's mostly for cosmetic and some smaller better time scoped operations (action, oauth, webhook). - Add expiration date to all operations - Cron to set `timeout` to all expired operations ## How to test? - Trigger an oauth but don't complete the process and wait 5-10minutes or - Add an operation, change the expiresAt manually, wait for the cron (The query in curl) ```sh #!/usr/bin/env bash curl -X POST "http://localhost:55132/20240528_messages.2024-05-30/_search" -H 'Content-Type: application/json' -d' { "query": { "bool": { "must": [{ "range": { "expiresAt": { "lt": "now" } } }], "must_not": { "exists": { "field": "parentId" } }, "should": [{ "term": { "state": "waiting" } }, { "term": { "state": "running" } }] } } } ' ```
- Loading branch information
1 parent
5ffdae6
commit 856d710
Showing
29 changed files
with
193 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as cron from 'node-cron'; | ||
import { errorManager, ErrorSourceEnum } from '@nangohq/shared'; | ||
import tracer from 'dd-trace'; | ||
import { envs, model } from '@nangohq/logs'; | ||
import { getLogger } from '@nangohq/utils'; | ||
|
||
const logger = getLogger('Jobs.TimeoutLogsOperations'); | ||
|
||
export function timeoutLogsOperations(): void { | ||
if (!envs.NANGO_LOGS_ENABLED) { | ||
return; | ||
} | ||
|
||
cron.schedule( | ||
'*/10 * * * *', | ||
// eslint-disable-next-line @typescript-eslint/no-misused-promises | ||
async () => { | ||
try { | ||
logger.info(`Timeouting old operations...`); | ||
await model.setTimeoutForAll(); | ||
} catch (err) { | ||
errorManager.report(err, { source: ErrorSourceEnum.PLATFORM }, tracer); | ||
} | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import { parseEnvs, ENVS } from '@nangohq/utils'; | ||
import { parseEnvs, ENVS, MAX_ACTION_DURATION, MAX_SYNC_DURATION, MAX_WEBHOOK_DURATION } from '@nangohq/utils'; | ||
|
||
// Do not require in community and enterprise right now | ||
const required = process.env['NANGO_LOGS_ENABLED'] === 'true'; | ||
|
||
export const envs = parseEnvs(required ? ENVS.required({ NANGO_LOGS_ES_URL: true, NANGO_LOGS_ES_USER: true, NANGO_LOGS_ES_PWD: true }) : ENVS); | ||
|
||
envs.NANGO_LOGS_ENABLED = Boolean(envs.NANGO_LOGS_ENABLED && envs.NANGO_LOGS_ES_URL); | ||
|
||
export const defaultOperationExpiration = { | ||
action: () => new Date(Date.now() + MAX_ACTION_DURATION).toISOString(), | ||
webhook: () => new Date(Date.now() + MAX_WEBHOOK_DURATION).toISOString(), | ||
sync: () => new Date(Date.now() + MAX_SYNC_DURATION).toISOString(), | ||
auth: () => new Date(Date.now() + 300 * 1000).toISOString() | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.