Skip to content

Commit

Permalink
fix: enable possibility to run remote runner (#2826)
Browse files Browse the repository at this point in the history
For enterprise customers who want to be able to run remote runner:
- Starting/Getting runner based on REMOTE_RUNNER_TYPE env var

## 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 Oct 10, 2024
1 parent 9879abf commit 16dda6c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/jobs/lib/execution/sync.integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect, describe, it, beforeAll, afterAll, vi } from 'vitest';
import db, { multipleMigrations } from '@nangohq/database';
import { envs } from '@nangohq/logs';
import type { UnencryptedRecordData, ReturnedRecord } from '@nangohq/records';
import { records as recordsService, format as recordsFormatter, migrate as migrateRecords, clearDbTestsOnly as clearRecordsDb } from '@nangohq/records';
import { handleSyncSuccess, startSync } from './sync.js';
import type { TaskSync } from '@nangohq/nango-orchestrator';
import type { Connection, Sync, SyncResult, Job as SyncJob, SyncConfig } from '@nangohq/shared';
import { isSyncJobRunning, seeders, getLatestSyncJob, updateSyncJobResult } from '@nangohq/shared';
import { Ok } from '@nangohq/utils';
import { envs } from '../env.js';

const mockStartScript = vi.fn(() => Promise.resolve(Ok(undefined)));

Expand Down
19 changes: 12 additions & 7 deletions packages/jobs/lib/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isEnterprise, env, getLogger } from '@nangohq/utils';
import type { ProxyAppRouter } from '@nangohq/nango-runner';
import type { KVStore } from '@nangohq/kvstore';
import { createKVStore } from '@nangohq/kvstore';
import { envs } from '../env.js';

const logger = getLogger('Runner');

Expand Down Expand Up @@ -54,12 +55,17 @@ export async function getOrStartRunner(runnerId: string): Promise<Runner> {
logger.error(err);
}
}
const isRender = process.env['IS_RENDER'] === 'true';
let runner: Runner;
if (isRender) {
runner = await RenderRunner.getOrStart(runnerId);
} else {
runner = await LocalRunner.getOrStart(runnerId);
switch (envs.RUNNER_TYPE) {
case 'LOCAL':
runner = await LocalRunner.getOrStart(runnerId);
break;
case 'REMOTE':
runner = await RemoteRunner.getOrStart(runnerId);
break;
case 'RENDER':
runner = await RenderRunner.getOrStart(runnerId);
break;
}

await waitForRunner(runner);
Expand All @@ -68,8 +74,7 @@ export async function getOrStartRunner(runnerId: string): Promise<Runner> {
}

export async function suspendRunner(runnerId: string): Promise<void> {
const isRender = process.env['IS_RENDER'] === 'true';
if (isRender) {
if (envs.RUNNER_TYPE === 'RENDER') {
// we only suspend render runners
const runner = await RenderRunner.get(runnerId);
if (runner) {
Expand Down
1 change: 1 addition & 0 deletions packages/utils/lib/environment/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const ENVS = z.object({
NANGO_JOBS_PORT: z.coerce.number().optional().default(3005),

// Runner
RUNNER_TYPE: z.enum(['LOCAL', 'REMOTE', 'RENDER']).default('LOCAL'),
RUNNER_SERVICE_URL: z.string().url().optional(),
NANGO_RUNNER_PATH: z.string().optional(),
RUNNER_OWNER_ID: z.string().optional(),
Expand Down
3 changes: 2 additions & 1 deletion vite.integration.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default defineConfig({
testTimeout: 20000,
env: {
NANGO_ENCRYPTION_KEY: 'RzV4ZGo5RlFKMm0wYWlXdDhxTFhwb3ZrUG5KNGg3TmU=',
NANGO_LOGS_ENABLED: 'true'
NANGO_LOGS_ENABLED: 'true',
ORCHESTRATOR_SERVICE_URL: 'http://orchestrator'
},
fileParallelism: false,
pool: 'forks'
Expand Down

0 comments on commit 16dda6c

Please sign in to comment.