Skip to content

Commit

Permalink
Create function to call API file from user
Browse files Browse the repository at this point in the history
Function is called from both sandbox and deployment environments
  • Loading branch information
ronitagarwala01 committed Nov 26, 2023
1 parent e01ece3 commit be574d8
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand All @@ -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
Expand All @@ -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 })
},

Expand Down

0 comments on commit be574d8

Please sign in to comment.