new(basic.gblib): New batch features.
This commit is contained in:
		
							parent
							
								
									77da28e980
								
							
						
					
					
						commit
						0177717f6e
					
				
					 4 changed files with 78 additions and 29 deletions
				
			
		| 
						 | 
					@ -530,7 +530,11 @@ export class DialogKeywords {
 | 
				
			||||||
  public async sendEmail({ pid, to, subject, body }) {
 | 
					  public async sendEmail({ pid, to, subject, body }) {
 | 
				
			||||||
    const { min, user } = await DialogKeywords.getProcessInfo(pid);
 | 
					    const { min, user } = await DialogKeywords.getProcessInfo(pid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!body) {
 | 
					    if (!process.env.EMAIL_FROM){
 | 
				
			||||||
 | 
					      return;                            
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!body ) {
 | 
				
			||||||
      body = "";
 | 
					      body = "";
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -638,11 +638,12 @@ export class GBVMService extends GBService {
 | 
				
			||||||
              // Expires token 10min. before or if it the first time, load it.
 | 
					              // Expires token 10min. before or if it the first time, load it.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              if (expiration < new Date().getTime() || firstTime) {
 | 
					              if (expiration < new Date().getTime() || firstTime) {
 | 
				
			||||||
                console.log ('Expired. Refreshing token...');
 | 
					                console.log (Expired. Refreshing token...' + expiration);
 | 
				
			||||||
                const {token, expiresOn} = await sys.getCustomToken({pid, tokenName});
 | 
					                const {token, expiresOn} = await sys.getCustomToken({pid, tokenName});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                global[tokenName] = token;
 | 
					                global[tokenName] = token;
 | 
				
			||||||
                global[tokenName + "_expiresOn"]= expiresOn; 
 | 
					                global[tokenName + "_expiresOn"]= expiresOn; 
 | 
				
			||||||
 | 
					                console.log (DONE:' + new Date(global[tokenName + "_expiresOn"]);;
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              if (__indexer == 0) {
 | 
					              if (__indexer == 0) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,7 +40,6 @@ import Path from 'path';
 | 
				
			||||||
 * Image processing services of conversation to be called by BASIC.
 | 
					 * Image processing services of conversation to be called by BASIC.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
export class KeywordsExpressions {
 | 
					export class KeywordsExpressions {
 | 
				
			||||||
 | 
					 | 
				
			||||||
  public static splitParamsButIgnoreCommasInDoublequotes = (str: string) => {
 | 
					  public static splitParamsButIgnoreCommasInDoublequotes = (str: string) => {
 | 
				
			||||||
    return str.split(',').reduce(
 | 
					    return str.split(',').reduce(
 | 
				
			||||||
      (accum, curr) => {
 | 
					      (accum, curr) => {
 | 
				
			||||||
| 
						 | 
					@ -50,7 +49,7 @@ export class KeywordsExpressions {
 | 
				
			||||||
          if (curr === '') {
 | 
					          if (curr === '') {
 | 
				
			||||||
            curr = null;
 | 
					            curr = null;
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
          accum.soFar.push(curr);
 | 
					          accum.soFar.push(curr?curr.trim(): '');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (curr.split('`').length % 2 == 0) {
 | 
					        if (curr.split('`').length % 2 == 0) {
 | 
				
			||||||
          accum.isConcatting = !accum.isConcatting;
 | 
					          accum.isConcatting = !accum.isConcatting;
 | 
				
			||||||
| 
						 | 
					@ -61,9 +60,7 @@ export class KeywordsExpressions {
 | 
				
			||||||
    ).soFar;
 | 
					    ).soFar;
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
  private static getParams = (text: string, names) => {
 | 
					  private static getParams = (text: string, names) => {
 | 
				
			||||||
 | 
					 | 
				
			||||||
    const items = KeywordsExpressions.splitParamsButIgnoreCommasInDoublequotes(text);
 | 
					    const items = KeywordsExpressions.splitParamsButIgnoreCommasInDoublequotes(text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let i = 0;
 | 
					    let i = 0;
 | 
				
			||||||
| 
						 | 
					@ -104,12 +101,10 @@ export class KeywordsExpressions {
 | 
				
			||||||
    keywords[i++] = [
 | 
					    keywords[i++] = [
 | 
				
			||||||
      /^\s*INPUT(.*)/gim,
 | 
					      /^\s*INPUT(.*)/gim,
 | 
				
			||||||
      ($0, $1, $2) => {
 | 
					      ($0, $1, $2) => {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        let separator;
 | 
					        let separator;
 | 
				
			||||||
        if ($1.indexOf(',') > -1) {
 | 
					        if ($1.indexOf(',') > -1) {
 | 
				
			||||||
          separator = ',';
 | 
					          separator = ',';
 | 
				
			||||||
        }
 | 
					        } else if ($1.indexOf(';') > -1) {
 | 
				
			||||||
        else if ($1.indexOf(';') > -1) {
 | 
					 | 
				
			||||||
          separator = ';';
 | 
					          separator = ';';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        let parts;
 | 
					        let parts;
 | 
				
			||||||
| 
						 | 
					@ -117,8 +112,7 @@ export class KeywordsExpressions {
 | 
				
			||||||
          return `
 | 
					          return `
 | 
				
			||||||
          TALK ${parts[0]}
 | 
					          TALK ${parts[0]}
 | 
				
			||||||
          HEAR ${parts[1]}`;
 | 
					          HEAR ${parts[1]}`;
 | 
				
			||||||
        }
 | 
					        } else {
 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
          return `
 | 
					          return `
 | 
				
			||||||
          HEAR ${$1}`;
 | 
					          HEAR ${$1}`;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -158,8 +152,7 @@ export class KeywordsExpressions {
 | 
				
			||||||
          let separator;
 | 
					          let separator;
 | 
				
			||||||
          if ($1.indexOf(',') > -1) {
 | 
					          if ($1.indexOf(',') > -1) {
 | 
				
			||||||
            separator = ',';
 | 
					            separator = ',';
 | 
				
			||||||
          }
 | 
					          } else if ($1.indexOf(';') > -1) {
 | 
				
			||||||
          else if ($1.indexOf(';') > -1) {
 | 
					 | 
				
			||||||
            separator = ';';
 | 
					            separator = ';';
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
          let items;
 | 
					          let items;
 | 
				
			||||||
| 
						 | 
					@ -205,9 +198,8 @@ export class KeywordsExpressions {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (kind === 'AS' && KeywordsExpressions.isNumber(sessionName)) {
 | 
					        if (kind === 'AS' && KeywordsExpressions.isNumber(sessionName)) {
 | 
				
			||||||
          const jParams = JSON.parse(`{${params}}`);
 | 
					          const jParams = JSON.parse(`{${params}}`);
 | 
				
			||||||
          const filename = `${jParams.url.substr(0, jParams.url.lastIndexOf("."))}.xlsx`;
 | 
					          const filename = `${jParams.url.substr(0, jParams.url.lastIndexOf('.'))}.xlsx`;
 | 
				
			||||||
          let code =
 | 
					          let code = `
 | 
				
			||||||
            `
 | 
					 | 
				
			||||||
           col = 1
 | 
					           col = 1
 | 
				
			||||||
           await sys.save({pid: pid,file: "${filename}", args: [id] })
 | 
					           await sys.save({pid: pid,file: "${filename}", args: [id] })
 | 
				
			||||||
           await dk.setFilter ({pid: pid, value:  "id=" + id })
 | 
					           await dk.setFilter ({pid: pid, value:  "id=" + id })
 | 
				
			||||||
| 
						 | 
					@ -255,7 +247,6 @@ export class KeywordsExpressions {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    keywords[i++] = [/^\s*for +(.*to.*)/gim, 'for ($1) {'];
 | 
					    keywords[i++] = [/^\s*for +(.*to.*)/gim, 'for ($1) {'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    keywords[i++] = [
 | 
					    keywords[i++] = [
 | 
				
			||||||
      /^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*pay\s*(.*)/gim,
 | 
					      /^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*pay\s*(.*)/gim,
 | 
				
			||||||
      ($0, $1, $2, $3) => {
 | 
					      ($0, $1, $2, $3) => {
 | 
				
			||||||
| 
						 | 
					@ -342,7 +333,6 @@ export class KeywordsExpressions {
 | 
				
			||||||
    keywords[i++] = [
 | 
					    keywords[i++] = [
 | 
				
			||||||
      /^\s*FOR EACH\s*(.*)\s*IN\s*(.*)/gim,
 | 
					      /^\s*FOR EACH\s*(.*)\s*IN\s*(.*)/gim,
 | 
				
			||||||
      ($0, $1, $2) => {
 | 
					      ($0, $1, $2) => {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        return `
 | 
					        return `
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
        __totalCalls = 10;
 | 
					        __totalCalls = 10;
 | 
				
			||||||
| 
						 | 
					@ -366,9 +356,9 @@ export class KeywordsExpressions {
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    keywords[i++] = [/^\s*next *$/gim,
 | 
					    keywords[i++] = [
 | 
				
			||||||
 | 
					      /^\s*next *$/gim,
 | 
				
			||||||
      ($0, $1, $2) => {
 | 
					      ($0, $1, $2) => {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        return `
 | 
					        return `
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
        __index = __index + 1;
 | 
					        __index = __index + 1;
 | 
				
			||||||
| 
						 | 
					@ -411,6 +401,64 @@ export class KeywordsExpressions {
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    keywords[i++] = [
 | 
				
			||||||
 | 
					      /^\s*synchronize\s*(.*)/gim,
 | 
				
			||||||
 | 
					      ($0, $1) => {
 | 
				
			||||||
 | 
					        const items = KeywordsExpressions.splitParamsButIgnoreCommasInDoublequotes($1);
 | 
				
			||||||
 | 
					        const [url, tableName, key1, pageVariable, limitVariable] = items;
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					        return `
 | 
				
			||||||
 | 
					         
 | 
				
			||||||
 | 
					            if (!limit) limit = 100;
 | 
				
			||||||
 | 
					            __page = 1
 | 
				
			||||||
 | 
					            while (__page > 0 && __page < pages) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              await retry(
 | 
				
			||||||
 | 
					                async (bail) => {
 | 
				
			||||||
 | 
					                  await ensureTokens();
 | 
				
			||||||
 | 
					                  __res  = await sys.getHttp ({pid: pid, file: host + '${url}' + '?' + pageVariable + '=' + __page + '&' + limitVariable + '=' +  limit, addressOrHeaders: headers, httpUsername, httpPs})
 | 
				
			||||||
 | 
					                },{ retries: 5});
 | 
				
			||||||
 | 
					              
 | 
				
			||||||
 | 
					              res  = __res
 | 
				
			||||||
 | 
					              list1 = res.data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              let j1 = 0
 | 
				
			||||||
 | 
					              items1  = []
 | 
				
			||||||
 | 
					              while (j1 < ubound(list1)) {
 | 
				
			||||||
 | 
					                detail_id = caseInsensitive(list1[j1])['${key1}']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                await retry(
 | 
				
			||||||
 | 
					                  async (bail) => {
 | 
				
			||||||
 | 
					                    await ensureTokens();
 | 
				
			||||||
 | 
					                    __res  = await sys.getHttp ({pid: pid, file: host + '${url}' + '/' + detail_id, addressOrHeaders: headers, httpUsername, httpPs})
 | 
				
			||||||
 | 
					                  },{ retries: 5});
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                res  = __res
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                items1[j1] = res.data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                j1 = j1 + 1
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					              __reportMerge1 = await sys.merge({pid: pid, file: '${tableName}' , data: items1 , key1: '${key1}'})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              __reportMerge.adds += __reportMerge1.adds;
 | 
				
			||||||
 | 
					              __reportMerge.updates += __reportMerge1.updates;
 | 
				
			||||||
 | 
					              __reportMerge.skipped += __reportMerge1.skipped;
 | 
				
			||||||
 | 
					              __reportMerge.title = __reportMerge1.title;
 | 
				
			||||||
 | 
					              REPORT = __report();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              __page = __page + 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              if (list1?.length < limit) {
 | 
				
			||||||
 | 
					                __page = 0
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					         `;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    keywords[i++] = [
 | 
					    keywords[i++] = [
 | 
				
			||||||
      /^\s*(.*)\=\s*(REWRITE)(\s*)(.*)/gim,
 | 
					      /^\s*(.*)\=\s*(REWRITE)(\s*)(.*)/gim,
 | 
				
			||||||
| 
						 | 
					@ -451,8 +499,7 @@ export class KeywordsExpressions {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (params[1]) {
 | 
					        if (params[1]) {
 | 
				
			||||||
          return `await sys.deleteFromStorage ({pid: pid, ${params}})`;
 | 
					          return `await sys.deleteFromStorage ({pid: pid, ${params}})`;
 | 
				
			||||||
        }
 | 
					        } else {
 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
          return `await sys.deleteFile ({pid: pid, ${params}})`;
 | 
					          return `await sys.deleteFile ({pid: pid, ${params}})`;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					@ -865,7 +912,6 @@ export class KeywordsExpressions {
 | 
				
			||||||
    keywords[i++] = [
 | 
					    keywords[i++] = [
 | 
				
			||||||
      /^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*post\s*(.*)/gim,
 | 
					      /^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*post\s*(.*)/gim,
 | 
				
			||||||
      ($0, $1, $2, $3) => {
 | 
					      ($0, $1, $2, $3) => {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        const args = $2.split(',');
 | 
					        const args = $2.split(',');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return `
 | 
					        return `
 | 
				
			||||||
| 
						 | 
					@ -972,13 +1018,12 @@ export class KeywordsExpressions {
 | 
				
			||||||
    keywords[i++] = [
 | 
					    keywords[i++] = [
 | 
				
			||||||
      /^\s*(talk)(\s*)(.*)/gim,
 | 
					      /^\s*(talk)(\s*)(.*)/gim,
 | 
				
			||||||
      ($0, $1, $2, $3) => {
 | 
					      ($0, $1, $2, $3) => {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        $3 = GBVMService.normalizeQuotes($3);
 | 
					        $3 = GBVMService.normalizeQuotes($3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // // Uses auto quote if this is a phrase with more then one word.
 | 
					        // // Uses auto quote if this is a phrase with more then one word.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!($3.trim().substr(0, 1) === '`' || $3.trim().substr(0, 1) === "'")) {
 | 
					        if (!($3.trim().substr(0, 1) === '`' || $3.trim().substr(0, 1) === "'")) {
 | 
				
			||||||
          $3 = "`" + $3 + "`";
 | 
					          $3 = '`' + $3 + '`';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return `await dk.talk ({pid: pid, text: ${$3}})`;
 | 
					        return `await dk.talk ({pid: pid, text: ${$3}})`;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					@ -1214,12 +1259,11 @@ export class KeywordsExpressions {
 | 
				
			||||||
        let index = 0;
 | 
					        let index = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        fields.forEach(field => {
 | 
					        fields.forEach(field => {
 | 
				
			||||||
 | 
					          // Extracts only the last part of the variable like 'column'
 | 
				
			||||||
          // Extracts only the last part of the variable like 'column' 
 | 
					 | 
				
			||||||
          // from 'row.column'.
 | 
					          // from 'row.column'.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          const fieldRegExp = /(?:.*\.)*(.*)/gim;
 | 
					          const fieldRegExp = /(?:.*\.)*(.*)/gim;
 | 
				
			||||||
          let name = fieldRegExp.exec(field.trim())[1]
 | 
					          let name = fieldRegExp.exec(field.trim())[1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          fieldsNamesOnly.push(`'${name}'`);
 | 
					          fieldsNamesOnly.push(`'${name}'`);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -751,7 +751,7 @@ export class SystemKeywords {
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        retries: 5,
 | 
					        retries: 5,
 | 
				
			||||||
        onRetry: err => {
 | 
					        onRetry: err => {
 | 
				
			||||||
          GBLog.error(`Retrying SaveToStorageBatch due to: ${err.message}.`);
 | 
					          GBLog.error(`Retrying SaveToStorageBatch due to: ${JSON.stringify(err)}.`);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue