Skip to content

Commit

Permalink
Merge pull request #105 from geodatagouv/tusbar/fix-enqueue-calls
Browse files Browse the repository at this point in the history
Fix publication issues
  • Loading branch information
tusbar committed Dec 10, 2018
2 parents 0014979 + 7a72f1d commit 0a66867
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
18 changes: 13 additions & 5 deletions plugins/publish-to-udata/geogw.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ const client = got.extend({
})

async function getRecord(recordId) {
const {body} = await client.get(`/records/${recordId}`, {
json: true
})

return body
try {
const {body} = await client.get(`/records/${recordId}`, {
json: true
})

return body
} catch (error) {
if (error.statusCode === 404) {
throw new Error('Record not found')
}

throw error
}
}

async function setRecordPublication(recordId, publicationInfo) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/publish-to-udata/jobs/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ module.exports = [
concurrency: 1,
options: {
jobId: 'unique', // Only one at a time
timeout: ms('20m')
timeout: ms('1h')
}
},

{
name: 'udata-sync-one',
concurrency: 10,
concurrency: 7,
options: {
jobIdKey: 'recordId'
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/publish-to-udata/jobs/udata-sync-one/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ exports.handler = async function ({data}) {
return publicationInfo.unpublish()
}

if (removeIfTargetDatasetNotFound === true && error.message === 'Target dataset doesn\'t exist anymore' && action === 'update') {
if (removeIfTargetDatasetNotFound === true && error.message === 'Target dataset doesnt exist anymore' && action === 'update') {
debug(`${recordId}: Target dataset not found. Going to remove the publication info…`)
return publicationInfo.removeAndNotify()
}
Expand Down
10 changes: 5 additions & 5 deletions plugins/publish-to-udata/models/Dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ schema.method('update', async function (options = {}) {
await this.transferTo(targetOrganization)
} catch (error) {
if (error.message === 'Dataset doesn’t exist') {
throw new Error('Target dataset doesnt exist anymore')
throw new Error('Target dataset doesn’t exist anymore')
}
throw error
}
Expand Down Expand Up @@ -151,7 +151,7 @@ schema.method('asyncUpdate', function (data = {}) {
throw new Error('Dataset not published')
}

return enqueue('udata-sync-one', {
return enqueue('udata-sync-one', `update: ${this._id}`, {
...data,
recordId: this._id,
action: 'update'
Expand Down Expand Up @@ -198,7 +198,7 @@ schema.method('asyncPublish', async function ({organizationId}) {
throw new Error('Dataset already published')
}

await enqueue('udata-sync-one', {
await enqueue('udata-sync-one', `publish: ${this._id}`, {
recordId: this._id,
action: 'publish',
organizationId
Expand Down Expand Up @@ -235,7 +235,7 @@ schema.method('asyncUnpublish', function () {
throw new Error('Dataset not published')
}

return enqueue('udata-sync-one', {
return enqueue('udata-sync-one', `unpublish: ${this._id}`, {
recordId: this._id,
action: 'unpublish'
})
Expand All @@ -252,7 +252,7 @@ schema.method('transferTo', async function (targetOrganization, force = false) {
})

schema.static('asyncSynchronizeAll', data => {
return enqueue('udata-sync-all', data)
return enqueue('udata-sync-all', 'udata-sync-all', data)
})

mongoose.model('Dataset', schema)

0 comments on commit 0a66867

Please sign in to comment.