|
|
@ -1,23 +1,31 @@ |
|
|
|
const { text } = require('express'); |
|
|
|
const emitter = require('../services/eventEmitter'); |
|
|
|
|
|
|
|
// Create a log function that logs the event name and the data
|
|
|
|
const log = (event, data) => { |
|
|
|
console.log(`----- Event: ${event} ----- `); |
|
|
|
console.log(data); |
|
|
|
console.log('-----'); |
|
|
|
}; |
|
|
|
|
|
|
|
// Create a new listener for the download.start event
|
|
|
|
emitter.on('download.start', ({ url, filepath }) => { |
|
|
|
console.log(`Downloading ${url} to ${filepath}`); |
|
|
|
log('download.start', `Downloading ${url} to ${filepath}`); |
|
|
|
}); |
|
|
|
|
|
|
|
// Create a new listener for the download.end event
|
|
|
|
emitter.on('download.end', ({ url, filepath }) => { |
|
|
|
console.log(`Downloaded ${url} to ${filepath}`); |
|
|
|
log('download.end', `Downloaded ${url} to ${filepath}`); |
|
|
|
}); |
|
|
|
|
|
|
|
// Create a new listener for the download.error event
|
|
|
|
emitter.on('download.error', ({ url, filepath, error, type }) => { |
|
|
|
console.error(`Error [${type}] downloading ${url} to ${filepath}: ${error}`); |
|
|
|
log('download.error', `Error [${type}] downloading ${url} to ${filepath}: ${error}`); |
|
|
|
}); |
|
|
|
|
|
|
|
// Create a new listener for the download.progress event
|
|
|
|
emitter.on('download.progress', ({ url, filepath, percentage }) => { |
|
|
|
console.log(`Downloaded ${percentage}% of ${url} to ${filepath}`); |
|
|
|
log('download.progress', `Downloaded ${percentage}% of ${url} to ${filepath}`); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -26,17 +34,17 @@ emitter.on('download.progress', ({ url, filepath, percentage }) => { |
|
|
|
|
|
|
|
// Create a new listener for the parseFromUrl.start event
|
|
|
|
emitter.on('parseFromUrl.start', ({ url, columns }) => { |
|
|
|
console.log(`Parsing ${url} with columns [${columns.join(', ')}]`); |
|
|
|
log('parseFromUrl.start', `Parsing ${url} with columns [${columns.join(', ')}]`); |
|
|
|
}); |
|
|
|
|
|
|
|
// Create a new listener for the parseFromUrl.end event
|
|
|
|
emitter.on('parseFromUrl.end', ({ url, columns, filepath }) => { |
|
|
|
console.log(`Parsed ${url} with columns ${columns.join(', ')} to ${filepath}`); |
|
|
|
log('parseFromUrl.end', `Parsed ${url} with columns ${columns.join(', ')} to ${filepath}`); |
|
|
|
}); |
|
|
|
|
|
|
|
// Create a new listener for the parseFromUrl.error event
|
|
|
|
emitter.on('parseFromUrl.error', ({ url, columns, error }) => { |
|
|
|
console.error(`Error parsing ${url} with columns ${columns.join(', ')}: ${error}`); |
|
|
|
log('parseFromUrl.error', `Error parsing ${url} with columns ${columns.join(', ')}: ${error}`); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -45,20 +53,20 @@ emitter.on('parseFromUrl.error', ({ url, columns, error }) => { |
|
|
|
|
|
|
|
// Create a new listener for the parse start event
|
|
|
|
emitter.on('parse.start', ({ filepath, columns, headers }) => { |
|
|
|
console.log(`Parsing ${filepath} with columns ${columns.join(', ')} and headers ${headers.join(', ')}`); |
|
|
|
log('parse.start', `Parsing ${filepath} with columns ${columns.join(', ')} and headers ${headers.join(', ')}`); |
|
|
|
}); |
|
|
|
|
|
|
|
// Create a new listener for the parse.end event
|
|
|
|
emitter.on('parse.end', ({ filepath, columns, count }) => { |
|
|
|
console.log(`Parsed ${filepath} with columns ${columns.join(', ')} and ${count} rows`); |
|
|
|
log('parse.end', `Parsed ${filepath} with columns ${columns.join(', ')} and ${count} rows`); |
|
|
|
}); |
|
|
|
|
|
|
|
// Create a new listener for the parse.error event
|
|
|
|
emitter.on('parse.error', ({ filepath, columns, error }) => { |
|
|
|
console.error(`Error parsing ${filepath} with columns ${columns.join(', ')}: ${error}`); |
|
|
|
log('parse.error', `Error parsing ${filepath} with columns ${columns.join(', ')}: ${error}`); |
|
|
|
}); |
|
|
|
|
|
|
|
// Create a new listener for the parse.data event
|
|
|
|
emitter.on('parse.data', ({ filepath, columns, data, index }) => { |
|
|
|
console.log(`Parsed ${filepath} with columns ${columns.join(', ')} at index ${index}`); |
|
|
|
log('parse.data', `Parsed ${filepath} with columns ${columns.join(', ')} at index ${index}`); |
|
|
|
}); |