Skip to content

Commit

Permalink
jobs: fix heartbeat (#1980)
Browse files Browse the repository at this point in the history
runningScripts used to be of type Record<string, context> but was
changed to a Map in
8a5520e
It caused the `Object.keys(this.runningScripts)` to always return an
empty array, which means no heartbeat have benn sent in 2 months

## Issue ticket number and link
https://linear.app/nango/issue/NAN-711/sync-frequency-issue

## Checklist before requesting a review (skip if just adding/editing
APIs & templates)
- [ ] I added tests, otherwise the reason is: 
- [ ] I added observability, otherwise the reason is:
- [ ] I added analytics, otherwise the reason is:
  • Loading branch information
TBonnin authored Apr 11, 2024
1 parent 15191ef commit 806d44c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/jobs/lib/integration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { createActivityLogMessage, localFileService, remoteFileService, NangoErr
import type { Runner } from './runner/runner.js';
import { getOrStartRunner, getRunnerId } from './runner/runner.js';
import tracer from 'dd-trace';
import { getLogger } from '@nangohq/utils/dist/logger.js';

const logger = getLogger('integration.service');

interface ScriptObject {
context: Context | null;
Expand Down Expand Up @@ -210,16 +213,17 @@ class IntegrationService implements IntegrationServiceInterface {

private sendHeartbeat() {
setInterval(() => {
Object.keys(this.runningScripts).forEach((syncId) => {
const scriptObject = this.runningScripts.get(syncId);

if (!scriptObject) {
return;
this.runningScripts.forEach((script, syncId) => {
const { context } = script;
if (context) {
try {
context.heartbeat();
} catch (error) {
logger.error(`Error sending heartbeat for syncId: ${syncId}`, error);
}
} else {
logger.error(`Error sending heartbeat for syncId ${syncId}: context not found`);
}

const { context } = scriptObject;

context?.heartbeat();
});
}, 300000);
}
Expand Down

0 comments on commit 806d44c

Please sign in to comment.