diff --git a/index.ts b/index.ts index e027293..4407bcc 100644 --- a/index.ts +++ b/index.ts @@ -35,6 +35,28 @@ function toCollectionName(name: string) { .slice(0, 32) } +async function call_API(cwd: string, node: string) { + //Load api call file and run all api calls to cluster + const api_path = join(cwd, openSearchApiFile) + let result + if (await exists(api_path)) { + console.log(`Found ${openSearchApiFile} file, deploying ML model`) + result = (await import(pathToFileURL(api_path).toString())).default + + //result should be a function that returns a promise + if (typeof result === 'function') { + result = result({ node: node }) + } + + //wait for the returned promise to resolve and thus all api calls to complete + if (result instanceof Promise) { + await result + } + } else { + console.log(`No ${openSearchApiFile} file found.`) + } +} + export const deploy = { // @ts-expect-error: The Architect plugins API has no type definitions. start({ cloudformation, inventory, arc, stage }) { @@ -59,6 +81,10 @@ export const deploy = { return serverlessServices } }, + // // @ts-expect-error: The Architect plugins API has no type definitions. + // end({ cloudformation, inventory }) { + // call_API(inventory.inv._project.cwd, ) + // }, } let local: LocalOpenSearch @@ -74,27 +100,7 @@ export const sandbox = { }, }) { local = await launch({}) - - //Load api call file and run all api calls to cluster - const api_path = join(cwd, openSearchApiFile) - let result - if (await exists(api_path)) { - console.log(`Found ${openSearchApiFile} file, deploying ML model`) - result = (await import(pathToFileURL(api_path).toString())).default - - //result should be a function that returns a promise - if (typeof result === 'function') { - result = result({ node: local.url }) - } - - //wait for the returned promise to resolve and thus all api calls to complete - if (result instanceof Promise) { - await result - } - } else { - console.log(`No ${openSearchApiFile} file found.`) - } - + await call_API(cwd, local.url) await populate(cwd, { node: local.url }) },