Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ coverage

# Build
build/

# IDE
.idea/**
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ Informs Squiss that you got a message that you're not planning on deleting, so t
### squiss.releaseMessage(Message)
Releases the given Message object back to the queue by setting its `VisibilityTimeout` to `0` and marking the message as handled internally. You can also call `message.release()` on the message itself to invoke this.

### squiss.purgeQueue()
Deletes all the messages in a queue and init in flight

### squiss.sendMessage(message, delay, attributes)
Sends an individual message to the configured queue, and returns a promise that resolves with AWS's official message metadata: an object containing `MessageId`, `MD5OfMessageAttributes`, and `MD5OfMessageBody`. Arguments:
- **message**. The message to push to the queue. If it's a string, great! If it's an Object, Squiss will call JSON.stringify on it.
Expand Down
17 changes: 17 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,23 @@ class Squiss extends EventEmitter {
})
}

/**
* Deletes all the messages in a queue and init in flight.
* @returns {Promise} Resolves on complete. Rejects with the official AWS SDK's error object.
*/
purgeQueue() {
return this.getQueueUrl().then((queueUrl) => {
return this.sqs.purgeQueue({ QueueUrl: queueUrl }).promise()
.then(data => {
this._inFlight = 0
this._delQueue = []
this._delTimer = null

return data
})
})
}

/**
* Sends an individual message to the configured queue.
* @param {string|Object} message The message to be sent. Objects will be JSON.stringified.
Expand Down
13 changes: 13 additions & 0 deletions test/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,19 @@ describe('index', () => {
})
})
})
describe('purgeQueue', () => {
it('calls SQS SDK purgeQueue method with queue URL', () => {
inst = new Squiss({ queueUrl: 'foo' })
inst.sqs = new SQSStub()
const spy = sinon.spy(inst.sqs, 'purgeQueue')
return inst.purgeQueue().then(() => {
spy.should.be.calledOnce()
spy.should.be.calledWith({ QueueUrl: 'foo' })
inst.sqs.msgs.length.should.equal(0)
inst.sqs.msgCount.should.equal(0)
})
})
})
describe('sendMessage', () => {
it('sends a string message with no extra arguments', () => {
inst = new Squiss({ queueUrl: 'foo' })
Expand Down
10 changes: 10 additions & 0 deletions test/stubs/SQSStub.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ class SQSStub extends EventEmitter {
})
}

purgeQueue() {
this.msgs = []
this.msgCount = 0
return this._makeReq(() => {
return Promise.resolve({
RequestId: '6fde8d1e-52cd-4581-8cd9-c512f4c64223'
})
})
}

sendMessage(params) {
this._addMessage(params.QueueUrl, params.MessageBody)
return this._makeReq(() => {
Expand Down