Skip to content
This repository has been archived by the owner on Dec 21, 2020. It is now read-only.

Commit

Permalink
Q: Half implemented queue cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pbeckingham committed May 13, 2018
1 parent 8c6c907 commit 57ba5f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Q.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <cmake.h>
#include <Q.h>
#include <Datetime.h>
#include <shared.h>
#include <sstream>
#include <iomanip>
Expand Down Expand Up @@ -201,3 +202,28 @@ std::vector <std::string> Q::events (const std::string& path) const
}

////////////////////////////////////////////////////////////////////////////////
// Scans the queue for events to remove.
int Q::cleanup () const
{
// Count the removals.
int count = 0;

// Calculate epoch 30 days ago.
Datetime now;
now -= 30 * 86400;
auto one_month_ago = now.toEpoch ();

for (const auto& entry : archive ())
{
File item (entry);
if (item.mtime () < one_month_ago)
{
//item.remove ();
++count;
}
}

return count;
}

////////////////////////////////////////////////////////////////////////////////
1 change: 1 addition & 0 deletions src/Q.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Q
bool destroy (bool force = false);
bool scan (std::string&);
void post (const std::string&) const;
int cleanup () const;

std::string activateEvent (const std::string&) const;
void archiveEvent (const std::string&) const;
Expand Down

0 comments on commit 57ba5f3

Please sign in to comment.