async function intitalFilesSyncSpawn() {
  const transaction = await sequelize.transaction();
  try {
    return new Promise(async (resolve, reject) => {
      /** 1. Scan - save files to DB */
      await scanAllToDB(ROOT_PATH, {
        filterDirs: IGNORED_PATH
      });
      /** 2. Upload to S3 */
      const syncToBucketSpawn$ = syncToBucketSpawn(ROOT_PATH, S3_BUCKET_URL, {
        shouldDelete: true,
        isInitial: true
      });
      syncToBucketSpawn$.subscribe({
        next(data) {
          log.info(`syncToBucketSpawn Next: ${data}`);
        },
        error(err) {
          reject(`Error from observable syncToBucketSpwan: ${err}`);
        },
        async complete(data) {
          log.info(`syncToBucketSpawn Complete: ${data}`);
          await transaction.commit();
          resolve(true);
        }
      });
    });
  } catch (err) {
    await transaction.rollback();
    throw new Error(`Error occurs in intitalFilesSyncSpawn: ${err.message}`);
  }
}
/** intitalFilesSyncSpawn - spawn version of the intitalFilesSync
 * 1. Scan all to the db under transaction from the Root Directory
 * 2. Upload files to S3 from the Root Directory
 * 3. If no error, commit the transaction
 * @return Promise<Boolean>
 */
spawn version of the intitalFilesSync
1. Scan all to the db under transaction from the Root Directory
2. Upload files to S3 from the Root Directory
3. If no error, commit the transaction
@return Promise
spawn version of the intitalFilesSync 1 . Scan all to the db under transaction from the Root Directory 2 . Upload files to S3 from the Root Directory 3 . If no error commit the transaction @return Promise
async function intitalFilesSyncSpawn() {
  const transaction = await sequelize.transaction();
  try {
    return new Promise(async (resolve, reject) => {
      await scanAllToDB(ROOT_PATH, {
        filterDirs: IGNORED_PATH
      });
      const syncToBucketSpawn$ = syncToBucketSpawn(ROOT_PATH, S3_BUCKET_URL, {
        shouldDelete: true,
        isInitial: true
      });
      syncToBucketSpawn$.subscribe({
        next(data) {
          log.info(`syncToBucketSpawn Next: ${data}`);
        },
        error(err) {
          reject(`Error from observable syncToBucketSpwan: ${err}`);
        },
        async complete(data) {
          log.info(`syncToBucketSpawn Complete: ${data}`);
          await transaction.commit();
          resolve(true);
        }
      });
    });
  } catch (err) {
    await transaction.rollback();
    throw new Error(`Error occurs in intitalFilesSyncSpawn: ${err.message}`);
  }
}
async function intitalFilesSyncSpawn ( ) { const transaction = await sequelize . transaction ( ) ; try { return new Promise ( async ( resolve , reject ) => { await scanAllToDB ( ROOT_PATH , { filterDirs : IGNORED_PATH } ) ; const syncToBucketSpawn$ = syncToBucketSpawn ( ROOT_PATH , S3_BUCKET_URL , { shouldDelete : true , isInitial : true } ) ; syncToBucketSpawn$ . subscribe ( { next ( data ) { log . info ( ` ${ data } ` ) ; } , error ( err ) { reject ( ` ${ err } ` ) ; } , async complete ( data ) { log . info ( ` ${ data } ` ) ; await transaction . commit ( ) ; resolve ( true ) ; } } ) ; } ) ; } catch ( err ) { await transaction . rollback ( ) ; throw new Error ( ` ${ err . message } ` ) ; } }
intitalFilesSyncSpawn - spawn version of the intitalFilesSync
 1.
intitalFilesSyncSpawn - spawn version of the intitalFilesSync 1 .
/** 1. Scan - save files to DB */ /** 2. Upload to S3 */