From e2052c698248c963d0c578a02eb9e9a9c6f5dbf1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 7 Mar 2017 21:31:28 +0000 Subject: Add basic timer task for automatically updating everything --- gentoobrowse-api/service/main.cpp | 2 +- gentoobrowse-api/service/maintenanceCommon.cpp | 30 +++++++++++++++++++++++++- gentoobrowse-api/service/maintenanceimpl.h | 4 +++- 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 #include #include "maintenance/abstractFileProcessor.h" +#include namespace Gentoo { namespace Service { @@ -19,7 +20,7 @@ namespace Gentoo { typedef boost::function FileHandleFunc; typedef std::map 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 static FileProcessorPtr createFileProessor(bool vcsMode); FileProcessorFactories fpfs; + IceUtil::TimerPtr taskRunner; }; } } -- cgit v1.2.3