summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-03-07 21:31:28 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2017-03-07 21:31:28 +0000
commite2052c698248c963d0c578a02eb9e9a9c6f5dbf1 (patch)
tree23c2e626cb4aad28afe09a80de711797cca58d45
parentSplit the abstract file processor out of maintenance common (diff)
downloadgentoobrowse-api-e2052c698248c963d0c578a02eb9e9a9c6f5dbf1.tar.bz2
gentoobrowse-api-e2052c698248c963d0c578a02eb9e9a9c6f5dbf1.tar.xz
gentoobrowse-api-e2052c698248c963d0c578a02eb9e9a9c6f5dbf1.zip
Add basic timer task for automatically updating everything
-rw-r--r--gentoobrowse-api/service/main.cpp2
-rw-r--r--gentoobrowse-api/service/maintenanceCommon.cpp30
-rw-r--r--gentoobrowse-api/service/maintenanceimpl.h4
3 files changed, 33 insertions, 3 deletions
diff --git a/gentoobrowse-api/service/main.cpp b/gentoobrowse-api/service/main.cpp
index 8ac8a8b..ce32be0 100644
--- a/gentoobrowse-api/service/main.cpp
+++ b/gentoobrowse-api/service/main.cpp
@@ -30,7 +30,7 @@ class Api : public IceTray::Service {
{
auto db = getConnectionPool(ic, "postgresql", "GentooBrowseAPI");
adp->add(new Portage(db), ic->stringToIdentity("portage"));
- adp->add(new Maintenance(db), ic->stringToIdentity("maintenance"));
+ adp->add(new Maintenance(db, ic, ic->getProperties()), ic->stringToIdentity("maintenance"));
adp->add(new Users(db), ic->stringToIdentity("users"));
adp->add(new Notifications(), ic->stringToIdentity("notifications"));
adp->add(new MailServer(), ic->stringToIdentity("mailserver"));
diff --git a/gentoobrowse-api/service/maintenanceCommon.cpp b/gentoobrowse-api/service/maintenanceCommon.cpp
index c2c96a3..e7590e3 100644
--- a/gentoobrowse-api/service/maintenanceCommon.cpp
+++ b/gentoobrowse-api/service/maintenanceCommon.cpp
@@ -9,14 +9,42 @@
namespace Gentoo {
namespace Service {
- Maintenance::Maintenance(IceTray::DatabasePoolPtr d) :
+ class AutoUpdatePackages : public IceUtil::TimerTask {
+ public:
+ AutoUpdatePackages(Ice::CommunicatorPtr i) : ic(i) { }
+
+ void runTimerTask() override {
+ auto m = MaintenancePrx::checkedCast(ic->stringToProxy("maintenance"));
+ m->ice_ping();
+ auto rb = m->begin_refreshBugs();
+ m->updateRepositories();
+ auto rptg = m->begin_refreshPackageTreeGit();
+ auto rcl = m->begin_refreshChangeLogs();
+ m->end_refreshPackageTreeGit(rptg);
+ m->sendNotifications();
+ m->end_refreshChangeLogs(rcl);
+ m->end_refreshBugs(rb);
+ }
+
+ private:
+ Ice::CommunicatorPtr ic;
+ };
+
+ Maintenance::Maintenance(IceTray::DatabasePoolPtr d, Ice::CommunicatorPtr ic, Ice::PropertiesPtr p) :
IceTray::AbstractDatabaseClient(d)
{
setupFileProcessors();
+ if (auto sync = p->getPropertyAsIntWithDefault("GentooBrowseAPI.SyncTime", 0) * 60) {
+ taskRunner = new IceUtil::Timer();
+ taskRunner->scheduleRepeated(new AutoUpdatePackages(ic), IceUtil::Time::seconds(sync));
+ }
}
Maintenance::~Maintenance()
{
+ if (taskRunner) {
+ taskRunner->destroy();
+ }
}
Ice::PropertiesPtr
diff --git a/gentoobrowse-api/service/maintenanceimpl.h b/gentoobrowse-api/service/maintenanceimpl.h
index b6b480a..a1f474b 100644
--- a/gentoobrowse-api/service/maintenanceimpl.h
+++ b/gentoobrowse-api/service/maintenanceimpl.h
@@ -9,6 +9,7 @@
#include <boost/function/function_fwd.hpp>
#include <converters.h>
#include "maintenance/abstractFileProcessor.h"
+#include <IceUtil/Timer.h>
namespace Gentoo {
namespace Service {
@@ -19,7 +20,7 @@ namespace Gentoo {
typedef boost::function<void(FileProcessorPtr, int64_t, const Gentoo::StringList &, const boost::filesystem::path &)> FileHandleFunc;
typedef std::map<int64_t, std::string> RepoMap;
- Maintenance(IceTray::DatabasePoolPtr d);
+ Maintenance(IceTray::DatabasePoolPtr d, Ice::CommunicatorPtr ic, Ice::PropertiesPtr p);
~Maintenance();
void refreshPackageTree(const Ice::Current &) override;
@@ -45,6 +46,7 @@ namespace Gentoo {
template <typename T>
static FileProcessorPtr createFileProessor(bool vcsMode);
FileProcessorFactories fpfs;
+ IceUtil::TimerPtr taskRunner;
};
}
}