Skip to content

Commit

Permalink
adds error logging to export worker
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfenton committed Nov 18, 2015
1 parent aaa854c commit a84bc58
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
### Changed
* Increase logging of errors in export worker

## [2.10.3] - 2015-11-10
### Fixed
* Remove 3 causes of unhandled exceptions in lib/geojson
Expand Down
48 changes: 35 additions & 13 deletions lib/ExportWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs.process('exports', concurrency, function (job, done) {
// All runtime errors will be funnelled through this function.
// That's why we throw errors instead of calling the callback
domain.on('error', function (err) {
koop.log.error('Error caught in domain', err)
handleError(job.data.table, job.data.key, err)
done(err)
})
Expand All @@ -60,7 +61,10 @@ jobs.process('exports', concurrency, function (job, done) {
// Jobs for removing files from the local FS
if (job.data.remove) return remove(job, done)
cache.getCount(job.data.table, job.data.options, function (err, count) {
if (err) throw err
if (err) {
koop.log.error('Error getting count from the DB', err)
throw err
}
// if we can handle the data in one page
if (count <= job.data.options.limit) {
singlePage(job, done)
Expand All @@ -84,10 +88,10 @@ jobs.process('exports', concurrency, function (job, done) {
*/
function handleError (table, key, error) {
cache.getInfo(table, function (err, info) {
if (err) koop.log.error(err)
if (err) koop.log.error('Error getting info from the db', table, err)
info.generating[key].error = {message: error.message}
cache.updateInfo(table, info, function (err) {
if (err) koop.log.error(err)
if (err) koop.log.error('Error updating info in the db', table, info, err)
})
})
}
Expand All @@ -105,7 +109,10 @@ function remove (job, done) {
var dir = path.join(files.localDir, 'files', (job.data.itemId + '_' + job.data.layerId))

rimraf(dir, function (err) {
if (err) throw err
if (err) {
koop.log.error('Error removing directories from file system', dir)
throw err
}
return done()
})
}
Expand All @@ -123,9 +130,15 @@ function singlePage (job, done) {
var options = job.data.options

cache.db.select(job.data.dbKey, options, function (err, geojson) {
if (err) throw err
if (err) {
koop.log.error('Error selecting rows from the DB', job.data.dbKey, options, err)
throw err
}
koop.Exporter.exportToFormat(format, job.data.dir, key, geojson[0], options, function (err, result) {
if (err) throw err
if (err) {
koop.log.error('Error during single page export', format, key, options, err)
throw err
}
done()
// just send over the pageLength in the third parameter
// this API is wonky so we just calc the progess on our own
Expand Down Expand Up @@ -188,13 +201,16 @@ function createFromVRT (job, done) {

try {
koop.Exporter.callOgr(params, geojson, job.data.options, function (err, formatFile) {
if (err) throw err
if (err) {
koop.log.error('Error calling OGR with VRT', params, job.data.options, err)
throw err
}
var paths = { paths: job.data.paths, file: formatFile }
done()
saveFile(job.data.table, job.data.format, job.data.key, job.data.options, paths)
})
} catch (e) {
koop.log.error('error calling OGR2OGR', e)
koop.log.error('error calling OGR2OGR with VRT', params, job.data.options, e)
throw e
}
}
Expand Down Expand Up @@ -252,7 +268,10 @@ var workerQ = async.queue(function (task, cb) {
var filePart = task.file
// TODO in koop-pgcache 2.0 this will be a geojson feature collection and not and array
cache.db.select(task.dbKey, opts, function (err, entry) {
if (err) throw err
if (err) {
koop.log.error('Error selecting rows from the DB', task.dbKey, opts, err)
throw err
}
if (fs.existsSync(filePart)) fs.unlinkSync(filePart)

fs.writeFile(filePart, JSON.stringify(entry[0]), function () {
Expand Down Expand Up @@ -291,13 +310,16 @@ workerQ.drain = function () {

try {
koop.Exporter.callOgr(params, geojson, job.data.options, function (err, formatFile) {
if (err) throw err
if (err) {
koop.log.error('Error calling OGR with VRT', params, job.data.options, err)
throw err
}
var paths = {paths: task.files, file: formatFile}
done()
saveFile(task.table, task.format, job.data.key, task.options, paths)
})
} catch (e) {
koop.log.error('error calling OGR2OGR', e)
koop.log.error('error calling OGR2OGR', params, job.data.options, e)
throw e
}
}
Expand All @@ -321,7 +343,7 @@ function saveFile (table, format, key, options, result, retried) {
if (err) {
// on the first failure retry tthis operation
if (!retried) return saveFile(table, format, key, options, result, true)
koop.log.error('Failed to write file to S3', err)
koop.log.error('Failed to write file to S3', table, format, key, err)
handleError(table, key, new Error('Error while writing to S3'))
}
try {
Expand All @@ -339,7 +361,7 @@ function saveFile (table, format, key, options, result, retried) {
}
files.copy(copyOpts, function (err) {
if (err) {
koop.log.error('Error while writing Latest file to S3', err)
koop.log.error('Error while writing Latest file to S3', copyOpts, err)
}
})
}
Expand Down

0 comments on commit a84bc58

Please sign in to comment.