async uploadData()

in marketing-analytics/activation/common-libs/nodejs-common/src/apis/analytics.js [91:140]


  async uploadData(data, config, batchId = 'unnamed') {
    const uploadConfig = Object.assign(
        {
          media: {
            mimeType: 'application/octet-stream',
            body: data,
          }
        },
        config);

    const analytics = await this.getApiClient();
    const response = await analytics.management.uploads.uploadData(
        uploadConfig);
    this.logger.debug('Configuration: ', config);
    this.logger.debug('Upload Data: ', data);
    this.logger.debug('Response: ', response);
    const job = /** @type {Schema$Upload} */ response.data;
    const uploadId = (/** @type {Schema$Upload} */job).id;
    this.logger.info(
        `Task [${batchId}] creates GA Data import job: ${uploadId}`);
    const jobConfig = Object.assign({uploadId}, config);
    const result = await Promise.race([
      this.checkJobStatus(jobConfig),
      wait(8 * 60 * 1000, job),  // wait up to 8 minutes here
    ]);
    /** @type {BatchResult} */ const batchResult = {};
    switch ((/** @type {Schema$Upload} */ result).status) {
      case 'FAILED':
        this.logger.error('GA Data Import failed', result);
        batchResult.result = false;
        batchResult.errors = result.errors
            || [`Unknown reason. ID: ${uploadId}`];
        break;
      case 'COMPLETED':
        this.logger.info(`GA Data Import job[${uploadId}] completed.`);
        this.logger.debug('Response: ', result);
        batchResult.result = true;
        break;
      case 'PENDING':
        this.logger.info('GA Data Import pending.', result);
        this.logger.info('Still will return true here.');
        batchResult.result = true;
        break;
      default:
        this.logger.error('Unknown results of GA Data Import: ', result);
        batchResult.result = false;
        batchResult.errors = [`Unknown status. ID: ${uploadId}`];
    }
    return batchResult;
  }