Example #1
0
        private void ScavengeByNumber(int deleteBatchSize)
        {
            if (ConfigurationManager.AppSettings["MaxDocsInDatabase"] == null) return;

            var maxDocs = long.Parse(ConfigurationManager.AppSettings["MaxDocsInDatabase"]);
            var options = new ViewOptions();
            options.StartKey.Add(MessageIdManager.Create(new DateTime(1970, 1, 1)).ToDocId());
            options.EndKey.Add(MessageIdManager.Create(DateTime.UtcNow).ToDocId());
            var db = new CouchClient(ConfigurationManager.AppSettings["HydraServer"], int.Parse(ConfigurationManager.AppSettings["Port"]), null, null, false, AuthenticationType.Basic).
                GetDatabase(ConfigurationManager.AppSettings["Database"]);
            // Getting the empty document returns general database info
            var deleteCount = db.GetDocument("").Value<long>("doc_count") - maxDocs;
            while (deleteCount > 0) {
                options.Limit = (int) Math.Min(deleteCount, deleteBatchSize);
                var rows = db.GetAllDocuments(options).Rows;
                if (!rows.Any()) break;
                DeleteDocs(rows, db);
                deleteCount -= deleteBatchSize;
            }
        }
Example #2
0
        private void ScavengeByDate(int deleteBatchSize)
        {
            if (ConfigurationManager.AppSettings["MessageExpiryDays"] == null) return;

            var expiryDays = double.Parse(ConfigurationManager.AppSettings["MessageExpiryDays"]);
            var options = new ViewOptions();
            options.StartKey.Add(MessageIdManager.Create(new DateTime(1970, 1, 1)).ToDocId());
            options.EndKey.Add(MessageIdManager.Create(DateTime.UtcNow.AddDays(-expiryDays)).ToDocId());
            options.Limit = deleteBatchSize;
            var db = new CouchClient(ConfigurationManager.AppSettings["HydraServer"], int.Parse(ConfigurationManager.AppSettings["Port"]), null, null, false, AuthenticationType.Basic).
                GetDatabase(ConfigurationManager.AppSettings["Database"]);
            var rows = db.GetAllDocuments(options).Rows;
            while (rows.Any()) {
                DeleteDocs(rows, db);
                rows = db.GetAllDocuments(options).Rows;
            }
        }