mirror of
https://github.com/openstf/stf
synced 2025-10-05 10:39:25 +02:00
Allow all pending transaction results to be cancelled.
This commit is contained in:
parent
f46540e51e
commit
b0400130ff
2 changed files with 32 additions and 7 deletions
|
@ -478,13 +478,12 @@ module.exports = function(options) {
|
|||
}
|
||||
})
|
||||
.catch(function(err) {
|
||||
var reply = wireutil.reply('storage')
|
||||
log.error('Storage upload had an error', err.stack)
|
||||
leaveChannel(responseChannel)
|
||||
push.send([
|
||||
channel
|
||||
, reply.fail('fail')
|
||||
])
|
||||
socket.emit('tx.cancel', responseChannel, {
|
||||
success: false
|
||||
, data: 'fail_upload'
|
||||
})
|
||||
})
|
||||
})
|
||||
.on('forward.test', function(channel, responseChannel, data) {
|
||||
|
|
|
@ -25,8 +25,17 @@ module.exports = function TransactionServiceFactory(socket) {
|
|||
}
|
||||
}
|
||||
|
||||
function cancelListener(someChannel, data) {
|
||||
if (someChannel === channel) {
|
||||
Object.keys(pending).forEach(function(source) {
|
||||
pending[source].cancel(data)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
socket.on('tx.done', doneListener)
|
||||
socket.on('tx.progress', progressListener)
|
||||
socket.on('tx.cancel', cancelListener)
|
||||
|
||||
this.channel = channel
|
||||
this.results = results
|
||||
|
@ -40,6 +49,7 @@ module.exports = function TransactionServiceFactory(socket) {
|
|||
.finally(function() {
|
||||
socket.removeListener('tx.done', doneListener)
|
||||
socket.removeListener('tx.progress', progressListener)
|
||||
socket.removeListener('tx.cancel', cancelListener)
|
||||
socket.emit('tx.cleanup', channel)
|
||||
})
|
||||
.progressed(function() {
|
||||
|
@ -67,8 +77,15 @@ module.exports = function TransactionServiceFactory(socket) {
|
|||
}
|
||||
}
|
||||
|
||||
function cancelListener(someChannel, data) {
|
||||
if (someChannel === channel) {
|
||||
pending.cancel(data)
|
||||
}
|
||||
}
|
||||
|
||||
socket.on('tx.done', doneListener)
|
||||
socket.on('tx.progress', progressListener)
|
||||
socket.on('tx.cancel', cancelListener)
|
||||
|
||||
this.channel = channel
|
||||
this.result = result
|
||||
|
@ -77,6 +94,7 @@ module.exports = function TransactionServiceFactory(socket) {
|
|||
.finally(function() {
|
||||
socket.removeListener('tx.done', doneListener)
|
||||
socket.removeListener('tx.progress', progressListener)
|
||||
socket.removeListener('tx.cancel', cancelListener)
|
||||
socket.emit('tx.cleanup', channel)
|
||||
})
|
||||
.progressed(function() {
|
||||
|
@ -90,7 +108,7 @@ module.exports = function TransactionServiceFactory(socket) {
|
|||
function PendingTransactionResult(result) {
|
||||
var resolver = Promise.defer()
|
||||
, seq = 0
|
||||
, last = null
|
||||
, last = Infinity
|
||||
, unplaced = []
|
||||
|
||||
resolver.promise.finally(function() {
|
||||
|
@ -102,7 +120,7 @@ module.exports = function TransactionServiceFactory(socket) {
|
|||
var message
|
||||
, foundAny = false
|
||||
|
||||
while ((message = unplaced[seq])) {
|
||||
while (seq <= last && (message = unplaced[seq])) {
|
||||
unplaced[seq] = void 0
|
||||
|
||||
if (seq === last) {
|
||||
|
@ -149,6 +167,14 @@ module.exports = function TransactionServiceFactory(socket) {
|
|||
readQueue()
|
||||
}
|
||||
|
||||
this.cancel = function(message) {
|
||||
if (!result.settled) {
|
||||
last = message.seq = seq
|
||||
unplaced[message.seq] = message
|
||||
readQueue()
|
||||
}
|
||||
}
|
||||
|
||||
this.result = result
|
||||
this.promise = resolver.promise
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue