Skip to content

Commit

Permalink
fix(jobs): move runner flags outside shared (#3083)
Browse files Browse the repository at this point in the history
## Changes

- Move RunnerFlags outside shared
It's only useful to jobs now
  • Loading branch information
bodinsamuel authored Nov 29, 2024
1 parent d1a4254 commit 9c19d7b
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ exports[`buildModelTs > should return empty (with sdk) 1`] = `
import { Nango } from '@nangohq/node';
import type { AxiosInstance, AxiosInterceptorManager, AxiosRequestConfig } from 'axios';
import type { SyncConfig } from '../models/Sync.js';
import type { RunnerFlags } from '../services/sync/run.utils.js';
import type { DBTeam } from '@nangohq/types';
import type { DBTeam, RunnerFlags } from '@nangohq/types';
export declare const oldLevelToNewLevel: {
readonly debug: "debug";
readonly info: "info";
Expand Down
5 changes: 3 additions & 2 deletions packages/jobs/lib/execution/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import {
configService,
environmentService,
errorManager,
featureFlags,
getApiUrl,
getRunnerFlags,
getSyncConfigRaw
} from '@nangohq/shared';
import { logContextGetter } from '@nangohq/logs';
import type { DBEnvironment, DBTeam } from '@nangohq/types';
import { startScript } from './operations/start.js';
import { bigQueryClient, slackService } from '../clients.js';
import { getRunnerFlags } from '../utils/flags.js';

export async function startAction(task: TaskAction): Promise<Result<void>> {
let account: DBTeam | undefined;
Expand Down Expand Up @@ -72,7 +73,7 @@ export async function startAction(task: TaskAction): Promise<Result<void>> {
attributes: syncConfig.attributes,
syncConfig: syncConfig,
debug: false,
runnerFlags: await getRunnerFlags(),
runnerFlags: await getRunnerFlags(featureFlags),
startedAt: new Date()
};

Expand Down
5 changes: 3 additions & 2 deletions packages/jobs/lib/execution/onEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { Err, metrics, Ok } from '@nangohq/utils';
import type { Result } from '@nangohq/utils';
import type { TaskOnEvent } from '@nangohq/nango-orchestrator';
import type { Config, SyncConfig, NangoConnection, NangoProps } from '@nangohq/shared';
import { configService, environmentService, getApiUrl, getRunnerFlags, NangoError } from '@nangohq/shared';
import { configService, environmentService, featureFlags, getApiUrl, NangoError } from '@nangohq/shared';
import { logContextGetter } from '@nangohq/logs';
import type { DBEnvironment, DBTeam } from '@nangohq/types';
import { startScript } from './operations/start.js';
import { bigQueryClient } from '../clients.js';
import { getRunnerFlags } from '../utils/flags.js';

export async function startOnEvent(task: TaskOnEvent): Promise<Result<void>> {
let account: DBTeam | undefined;
Expand Down Expand Up @@ -70,7 +71,7 @@ export async function startOnEvent(task: TaskOnEvent): Promise<Result<void>> {
nangoConnectionId: task.connection.id,
syncConfig: syncConfig,
debug: false,
runnerFlags: await getRunnerFlags(),
runnerFlags: await getRunnerFlags(featureFlags),
startedAt: new Date()
};

Expand Down
7 changes: 4 additions & 3 deletions packages/jobs/lib/execution/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
externalWebhookService,
getApiUrl,
getLastSyncDate,
getRunnerFlags,
updateSyncJobStatus,
SyncStatus,
errorManager,
Expand All @@ -21,7 +20,8 @@ import {
configService,
createSyncJob,
getSyncConfigRaw,
getSyncJobByRunId
getSyncJobByRunId,
featureFlags
} from '@nangohq/shared';
import { Err, Ok, metrics } from '@nangohq/utils';
import type { Result } from '@nangohq/utils';
Expand All @@ -35,6 +35,7 @@ import { records } from '@nangohq/records';
import type { TaskSync, TaskSyncAbort } from '@nangohq/nango-orchestrator';
import { abortScript } from './operations/abort.js';
import { logger } from '../logger.js';
import { getRunnerFlags } from '../utils/flags.js';

export async function startSync(task: TaskSync, startScriptFn = startScript): Promise<Result<NangoProps>> {
let logCtx: LogContext | undefined;
Expand Down Expand Up @@ -130,7 +131,7 @@ export async function startSync(task: TaskSync, startScriptFn = startScript): Pr
track_deletes: syncConfig.track_deletes,
syncConfig: syncConfig,
debug: task.debug || false,
runnerFlags: await getRunnerFlags(),
runnerFlags: await getRunnerFlags(featureFlags),
startedAt: new Date(),
...(lastSyncDate ? { lastSyncDate } : {})
};
Expand Down
5 changes: 3 additions & 2 deletions packages/jobs/lib/execution/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
createSyncJob,
environmentService,
externalWebhookService,
featureFlags,
getApiUrl,
getRunnerFlags,
getSyncByIdAndName,
getSyncConfigRaw,
updateSyncJobStatus
Expand All @@ -22,6 +22,7 @@ import { logContextGetter } from '@nangohq/logs';
import type { DBEnvironment, DBTeam } from '@nangohq/types';
import { startScript } from './operations/start.js';
import { sendSync as sendSyncWebhook } from '@nangohq/webhooks';
import { getRunnerFlags } from '../utils/flags.js';

export async function startWebhook(task: TaskWebhook): Promise<Result<void>> {
let team: DBTeam | undefined;
Expand Down Expand Up @@ -102,7 +103,7 @@ export async function startWebhook(task: TaskWebhook): Promise<Result<void>> {
syncId: sync.id,
syncJobId: syncJob.id,
debug: false,
runnerFlags: await getRunnerFlags(),
runnerFlags: await getRunnerFlags(featureFlags),
startedAt: new Date()
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import featureFlags from '../../utils/featureflags.js';
import type { FeatureFlags } from '@nangohq/shared';
import type { RunnerFlags } from '@nangohq/types';

export interface RunnerFlags {
validateActionInput: boolean;
validateActionOutput: boolean;
validateSyncRecords: boolean;
validateSyncMetadata: boolean;
}

export async function getRunnerFlags(): Promise<RunnerFlags> {
export async function getRunnerFlags(featureFlags: FeatureFlags): Promise<RunnerFlags> {
const [validateActionInput, validateActionOutput, validateSyncRecords, validateSyncMetadata] = await Promise.all([
featureFlags.isEnabled('runner.validateActionInput', 'global', false),
featureFlags.isEnabled('runner.validateActionOutput', 'global', false),
Expand Down
6 changes: 3 additions & 3 deletions packages/logs/lib/es/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { getFormattedMessage } from '../models/helpers.js';

export async function start() {
if (!envs.NANGO_LOGS_ENABLED) {
logger.warning('OpenSearch is disabled, skipping');
logger.warning('Elasticsearch is disabled, skipping');
return;
}

logger.info('🔄 OpenSearch service starting...');
logger.info('🔄 Elasticsearch service starting...');

await migrateMapping();

logger.info('✅ OpenSearch');
logger.info('✅ Elasticsearch');
}

export async function migrateMapping() {
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ import syncManager, { syncCommandToOperation } from './services/sync/manager.ser
import flowService from './services/flow.service.js';
import { errorNotificationService } from './services/notification/error.service.js';
import analytics, { AnalyticsTypes } from './utils/analytics.js';
import featureFlags from './utils/featureflags.js';
import featureFlags, { FeatureFlags } from './utils/featureflags.js';
import { Orchestrator } from './clients/orchestrator.js';
import { SlackService, generateSlackConnectionId } from './services/notification/slack.service.js';

export * from './services/on-event-scripts.service.js';
export * from './services/sync/sync.service.js';
export * from './services/sync/job.service.js';
export * from './services/sync/run.utils.js';
export * from './services/sync/config/config.service.js';
export * from './services/sync/config/endpoint.service.js';
export * from './services/sync/config/deploy.service.js';
Expand Down Expand Up @@ -79,6 +78,7 @@ export {
errorNotificationService,
analytics,
AnalyticsTypes,
FeatureFlags,
featureFlags,
syncCommandToOperation,
Orchestrator,
Expand Down
3 changes: 1 addition & 2 deletions packages/shared/lib/sdk/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import {
truncateJson
} from '@nangohq/utils';
import type { SyncConfig } from '../models/Sync.js';
import type { RunnerFlags } from '../services/sync/run.utils.js';
import type { ValidateDataError } from './dataValidation.js';
import { validateData } from './dataValidation.js';
import { NangoError } from '../utils/error.js';
import type { DBTeam, GetPublicIntegration, MessageRowInsert } from '@nangohq/types';
import type { DBTeam, GetPublicIntegration, MessageRowInsert, RunnerFlags } from '@nangohq/types';
import { getProvider } from '../services/providers.js';

const logger = getLogger('SDK');
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/lib/utils/featureflags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getRedisUrl } from './utils.js';

const logger = getLogger('FeatureFlags');

class FeatureFlags {
export class FeatureFlags {
redis: RedisKVStore | undefined;

constructor(redis: RedisKVStore | undefined) {
Expand Down
7 changes: 7 additions & 0 deletions packages/types/lib/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ export interface RunnerOutput {
error: RunnerOutputError | null;
response?: any; // TODO: define response type
}

export interface RunnerFlags {
validateActionInput: boolean;
validateActionOutput: boolean;
validateSyncRecords: boolean;
validateSyncMetadata: boolean;
}

0 comments on commit 9c19d7b

Please sign in to comment.