Last active
March 26, 2019 20:58
-
-
Save binario200/8655825a7db821414a9e52a4a7c4d899 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function createResource(req,res) { | |
try { | |
// cuando utilizar await y cuando no ? | |
// processResource puede tomar 2 o 3 minutos por eso creo que no deberia tener await | |
// para no tener esperando la respuesta del endpoint hasta que termine | |
processResourceRequest(); | |
return res.status(HTTPStatuses.CREATED).json(resourceId); | |
} catch { | |
return res.status(HTTPStatuses.BAD_REQUEST).json(error); | |
} | |
} | |
export const processResourceRequest = async (resourceId, hostName) => { | |
try { | |
// cualquier numero de llamadas a funciones incluyendo api calls y mongo | |
//ahi si usando await | |
const resource = await Resource.findByid(...): | |
runTerraformForResource(resourceId); | |
} catch (e) { | |
throw new Error('Error at resource.controller.processResourceRequest :' + e); | |
} | |
} | |
// la duda del for // esta bin definida la funcion o deberia usar promise.resolve or reject ? | |
async function checkForHostinAD(searchstring) { | |
let hostFound = false; | |
let result; | |
for (let i = 0, len = ldapQueryOptions.length; i < len; i++) { | |
result = await queryLdapForHost(searchstring, ldapQueryOptions[i]); | |
if(result && (result.entries.length > 0)) { | |
console.log('Record found in AD: ' + result.entries[0].distinguishedName) | |
hostFound = true; | |
break; | |
} | |
} | |
return hostFound; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment