diff --git a/docs/guide.md b/docs/guide.md index eb29bd96..2a5a2dc1 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -151,12 +151,10 @@ useful as a throttling mechanism when using a queue as a way to delay work. Queue expiration ---------------- -Queues can be configure to expire whole queues as well. When a queue is -created the time is noted. It is periodically (see the aforementioned -`expirationTimerFrequency`) checked against the current time and the -`maxQueueAge` configuration option. If the queue is *empty* and the current time -is greater than create time + `maxQueueAge` then the queue is ready to be -expired and will be deleted. +Whole queues can be configured to expire as well. If `maxQueueAge` is set +`expirationTimerFrequency` is used to check the queue age. If the queue is +empty, and it has been longer than `maxQueueAge` since it was created then +the queue will be deleted. A `maxQueueAge` of zero, which is usually the default, means a queue never expires. @@ -180,7 +178,6 @@ is created, and it will start receiving new items written to the parent queue. Existing items are not copied over. A fanout queue can be deleted to stop it from receiving new items. - Memcache commands ----------------- diff --git a/src/main/scala/net/lag/kestrel/Kestrel.scala b/src/main/scala/net/lag/kestrel/Kestrel.scala index 0a94e703..b576f19d 100644 --- a/src/main/scala/net/lag/kestrel/Kestrel.scala +++ b/src/main/scala/net/lag/kestrel/Kestrel.scala @@ -154,6 +154,8 @@ class Kestrel(defaultQueueConfig: QueueConfig, builders: List[QueueBuilder], if (expired > 0) { log.info("Expired %d item(s) from queues automatically.", expired) } + // Now that we've cleaned out the queue, lets see if any of them are + // ready to be expired. Kestrel.this.queueCollection.deleteExpiredQueues() } }.start() diff --git a/src/main/scala/net/lag/kestrel/PersistentQueue.scala b/src/main/scala/net/lag/kestrel/PersistentQueue.scala index daca3a3d..48b41dd2 100644 --- a/src/main/scala/net/lag/kestrel/PersistentQueue.scala +++ b/src/main/scala/net/lag/kestrel/PersistentQueue.scala @@ -148,14 +148,10 @@ class PersistentQueue(val name: String, persistencePath: String, @volatile var c */ def isReadyForExpiration: Boolean = { // Don't even bother if the maxQueueAge is None - if(config.maxQueueAge.isDefined && config.maxQueueAge.get == None) { - false + if(config.maxQueueAge.isDefined && queue.isEmpty && Time.now > _createTime + config.maxQueueAge.get) { + true } else { - if(queue.isEmpty && config.maxQueueAge.isDefined && Time.now > _createTime + config.maxQueueAge.get) { - true - } else { - false - } + false } } diff --git a/src/main/scala/net/lag/kestrel/QueueCollection.scala b/src/main/scala/net/lag/kestrel/QueueCollection.scala index 000edadf..d628033e 100644 --- a/src/main/scala/net/lag/kestrel/QueueCollection.scala +++ b/src/main/scala/net/lag/kestrel/QueueCollection.scala @@ -198,10 +198,9 @@ class QueueCollection(queueFolder: String, timer: Timer, journalSyncScheduler: S } def expireQueue(name: String): Unit = { - - if(!shuttingDown) { + if (!shuttingDown) { queues.get(name) map { q => - if(q.isReadyForExpiration) { + if (q.isReadyForExpiration) { delete(name) Stats.incr("queue_expires") log.info("Expired queue %s", name) @@ -217,8 +216,6 @@ class QueueCollection(queueFolder: String, timer: Timer, journalSyncScheduler: S def deleteExpiredQueues(): Unit = { - // Now that we've cleaned out the queue, lets see if any of them are - // ready to be expired. queueNames.map { qName => expireQueue(qName) } }