while (true) {
const result = await sql.query(`
SELECT TOP (1) *
FROM ${originalTable}
WHERE IdentifiedState = 0 AND Email <> '' AND AnalyticsAppID = ${AnalyticsAppID}
ORDER BY InsertDate
`);
if (result.setOfRecords.length == 0) {
break
}
for (let i = 0; i < result.setOfRecords.length; i++) {
const item = result.setOfRecords[i]
let UserProperty = {}
let DBEmail = item['Email'];
UserFields.forEach(i => {
let j = i;
if (i == 'FirstName') { j = 'firstName'; }
if (i == 'LastName') { j = 'lastName'; }
if (i == 'Email') {
item[i] = item[i].split(";")[0];
item[i] = item[i].split(",")[0];
item[i] = item[i].replace("$", "@");
item[i] = item[i].toLowerCase()
j = 'email';
}
UserProperty[j] = item[i];
});
if (validateEmail(UserProperty['email']) && UserProperty['email'].length > 10) {
try {
await analytics.identify({
userId: UserProperty['email'],
traits: UserProperty
});
console.log('Successful')
}
catch (error) {
console.log('Error: ', error);
}
finally {
console.log(originalTable, DBEmail, UserProperty['email']);
}
}
await sql.query(`
UPDATE ${originalTable}
SET IdentifiedState = 1
WHERE AnalyticsAppID = ${AnalyticsAppID} AND Email = '${DBEmail}' `
);
}
}
I have this ETL script, but it ends up in a Timeout exception. I am wondering if there's a need to make the script stronger. Because it loops endlessly and I am wondering what's the best practices with these types of scripts.