diff --git a/app.ts b/app.ts index 95fdbf5a9..490a2769d 100755 --- a/app.ts +++ b/app.ts @@ -524,7 +524,12 @@ async function main() { const clientOptionsHandler = new ClientOptionsHandler(sources, compilerProps, defArgs); const compilationQueue = CompilationQueue.fromProps(compilerProps.ceProps); - const compilationEnvironment = new CompilationEnvironment(compilerProps, compilationQueue, defArgs.doCache); + const compilationEnvironment = new CompilationEnvironment( + compilerProps, + awsProps, + compilationQueue, + defArgs.doCache, + ); const compileHandler = new CompileHandler(compilationEnvironment, awsProps); const storageType = getStorageTypeByKey(storageSolution); const storageHandler = new storageType(httpRoot, compilerProps, awsProps); @@ -887,7 +892,7 @@ async function main() { setupEventLoopLagLogging(); if (isExecutionWorker) { - const queue = new SqsWorkerMode(ceProps); + const queue = new SqsWorkerMode(ceProps, awsProps); const doExecutionWork = async () => { const msg = await queue.pop(); if (msg && msg.guid) { diff --git a/lib/compilation-env.ts b/lib/compilation-env.ts index f58535a18..7182e9b58 100644 --- a/lib/compilation-env.ts +++ b/lib/compilation-env.ts @@ -45,6 +45,7 @@ type PropFunc = (string, any?) => any; export class CompilationEnvironment { ceProps: PropertyGetter; + awsProps: PropertyGetter; compilationQueue: CompilationQueue; compilerProps: CompilerProps; okOptions: RegExp; @@ -60,8 +61,9 @@ export class CompilationEnvironment { statsNoter: IStatsNoter; private logCompilerCacheAccesses: boolean; - constructor(compilerProps, compilationQueue, doCache) { + constructor(compilerProps, awsProps, compilationQueue, doCache) { this.ceProps = compilerProps.ceProps; + this.awsProps = awsProps; this.compilationQueue = compilationQueue; this.compilerProps = compilerProps.get.bind(compilerProps); // So people running local instances don't break suddenly when updating diff --git a/lib/execution/remote-execution-env.ts b/lib/execution/remote-execution-env.ts index 9705097e5..c56320e36 100644 --- a/lib/execution/remote-execution-env.ts +++ b/lib/execution/remote-execution-env.ts @@ -22,7 +22,7 @@ export class RemoteExecutionEnvironment implements IExecutionEnvironment { this.triple = triple; this.guid = crypto.randomUUID(); this.packageHash = executablePackageHash; - this.execQueue = new SqsExecuteRequester(environment.ceProps); + this.execQueue = new SqsExecuteRequester(environment.ceProps, environment.awsProps); logger.info( `RemoteExecutionEnvironment with ${triple.toString()} and ${executablePackageHash} - guid ${this.guid}`, diff --git a/lib/execution/sqs-execution-queue.ts b/lib/execution/sqs-execution-queue.ts index 3d56c9c64..7f7295977 100644 --- a/lib/execution/sqs-execution-queue.ts +++ b/lib/execution/sqs-execution-queue.ts @@ -17,8 +17,9 @@ export class SqsExecuteQueueBase { protected sqs: SQS; protected queue_url: string; - constructor(props: PropertyGetter) { - this.sqs = new SQS(); + constructor(props: PropertyGetter, awsProps: PropertyGetter) { + const region = awsProps('region', ''); + this.sqs = new SQS({region: region}); this.queue_url = props('execqueue.queue_url', ''); if (this.queue_url === '') throw new Error('execqueue.queue_url property required'); } @@ -43,8 +44,8 @@ export class SqsExecuteRequester extends SqsExecuteQueueBase { export class SqsWorkerMode extends SqsExecuteQueueBase { protected triple: ExecutionTriple; - constructor(props: PropertyGetter) { - super(props); + constructor(props: PropertyGetter, awsProps: PropertyGetter) { + super(props, awsProps); this.triple = new ExecutionTriple(); // this.triple.setInstructionSet('aarch64'); // test // todo: determine and set specialty somehow diff --git a/test/compilation-env.ts b/test/compilation-env.ts index 68a72e570..4e5177f89 100644 --- a/test/compilation-env.ts +++ b/test/compilation-env.ts @@ -43,28 +43,28 @@ describe('Compilation environment', () => { it('Should cache by default', async () => { // TODO: Work will need to be done here when CompilationEnvironment's constructor is typed better - const ce = new CompilationEnvironment(compilerProps, undefined, undefined); + const ce = new CompilationEnvironment(compilerProps, fakeProps, undefined, undefined); await expect(ce.cacheGet('foo')).resolves.toBeNull(); await ce.cachePut('foo', {res: 'bar'}, undefined); await expect(ce.cacheGet('foo')).resolves.toEqual({res: 'bar'}); await expect(ce.cacheGet('baz')).resolves.toBeNull(); }); it('Should cache when asked', async () => { - const ce = new CompilationEnvironment(compilerProps, undefined, true); + const ce = new CompilationEnvironment(compilerProps, fakeProps, undefined, true); await expect(ce.cacheGet('foo')).resolves.toBeNull(); await ce.cachePut('foo', {res: 'bar'}, undefined); await expect(ce.cacheGet('foo')).resolves.toEqual({res: 'bar'}); }); it("Shouldn't cache when asked", async () => { // TODO: Work will need to be done here when CompilationEnvironment's constructor is typed better - const ce = new CompilationEnvironment(compilerProps, undefined, false); + const ce = new CompilationEnvironment(compilerProps, fakeProps, undefined, false); await expect(ce.cacheGet('foo')).resolves.toBeNull(); await ce.cachePut('foo', {res: 'bar'}, undefined); await expect(ce.cacheGet('foo')).resolves.toBeNull(); }); it('Should filter bad options', () => { // TODO: Work will need to be done here when CompilationEnvironment's constructor is typed better - const ce = new CompilationEnvironment(compilerProps, undefined, undefined); + const ce = new CompilationEnvironment(compilerProps, fakeProps, undefined, undefined); expect(ce.findBadOptions(['-O3', '-flto'])).toEqual([]); expect(ce.findBadOptions(['-O3', '-plugin'])).toEqual(['-plugin']); }); diff --git a/test/utils.ts b/test/utils.ts index 174f46177..5457b2a4f 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -41,7 +41,7 @@ import {Language} from '../types/languages.interfaces.js'; export function makeCompilationEnvironment(options: Record): CompilationEnvironment { const compilerProps = new CompilerProps(options.languages, fakeProps(options.props || {})); const compilationQueue = options.queue || new CompilationQueue(options.concurrency || 1, options.timeout, 100_000); - return new CompilationEnvironment(compilerProps, compilationQueue, options.doCache); + return new CompilationEnvironment(compilerProps, fakeProps, compilationQueue, options.doCache); } export function makeFakeCompilerInfo(props: Partial): CompilerInfo {