Commit ba5eabbc authored by Alexandros Georgantas's avatar Alexandros Georgantas

chore(db): revert uploading state of book component

parent bc99cc17
const logger = require('@pubsweet/logger')
const { editoriaDataModel } = require('editoria-data-model')
const map = require('lodash/map')
const { models } = editoriaDataModel
const { BookComponentState } = models
const unfreezeUploading = async () => {
try {
const hanged = await BookComponentState.query().where('uploading', true)
logger.info(`Found ${hanged.length} with hanging uploading`)
await Promise.all(
map(hanged, async bookcomponentState => {
logger.info(`Unfreezing ${bookcomponentState.id}`)
return BookComponentState.query().patchAndFetchById(
bookcomponentState.id,
{
uploading: false,
},
)
}),
)
const after = await BookComponentState.query().where('uploading', true)
if (after.length === 0) {
logger.info('Job done')
} else {
logger.info(`Remaining ${after}`)
}
} catch (e) {
throw new Error(e)
}
}
module.exports = unfreezeUploading
unfreezeUploading()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment