Skip to content

running the seeder in v6 #4523

Answered by RomainLanz
jasonejavier asked this question in Help
Discussion options

You must be logged in to vote

Hey @jasonejavier! 👋🏻

Since you are using a stream, you are not properly awaiting the end of your processing.

I would recommend creating a dedicated method that does the processing and makes it return a promise.
Something like:

export default class extends BaseSeeder {
  async run() {
    // ...
    
    await this.#processsCsvFile(csvFilePath)
  }
  
  async #proccessCsvFile(filePath: string) {
    return new Promise((resolve, reject) => {
      createReadStream(csvFilePath)
        .on('end', () => {
          // ...
          resolve()
        })
        .on('error', () => {
          // ...
          reject()
        })
    })
  }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jasonejavier
Comment options

Answer selected by jasonejavier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants