summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2018-03-04 17:29:02 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2018-03-04 17:29:02 +0000
commit11c18c162b858fd62d6734eeca6214fe2d70548c (patch)
tree27e6813295193f108ce99838e921963ddab7e089
parentAdd a test user we never verify (diff)
downloadgentoobrowse-api-11c18c162b858fd62d6734eeca6214fe2d70548c.tar.bz2
gentoobrowse-api-11c18c162b858fd62d6734eeca6214fe2d70548c.tar.xz
gentoobrowse-api-11c18c162b858fd62d6734eeca6214fe2d70548c.zip
Refactor timer task setup to make it simplier, more generic
-rw-r--r--gentoobrowse-api/service/maintenanceCommon.cpp45
-rw-r--r--gentoobrowse-api/service/maintenanceimpl.h2
2 files changed, 36 insertions, 11 deletions
diff --git a/gentoobrowse-api/service/maintenanceCommon.cpp b/gentoobrowse-api/service/maintenanceCommon.cpp
index 4a11ed2..8b0c810 100644
--- a/gentoobrowse-api/service/maintenanceCommon.cpp
+++ b/gentoobrowse-api/service/maintenanceCommon.cpp
@@ -9,31 +9,42 @@
namespace Gentoo {
namespace Service {
- class AutoUpdatePackages : public IceUtil::TimerTask {
+ class BaseScheduledTask : public IceUtil::TimerTask {
public:
- AutoUpdatePackages(Ice::CommunicatorPtr i) : ic(i) { }
+ BaseScheduledTask(Ice::CommunicatorPtr i) : ic(i)
+ {
+ }
+
+ protected:
+ template<typename Proxy>
+ Proxy getProxy(const std::string & n) const {
+ auto p = Proxy::checkedCast(ic->stringToProxy(n));
+ p->ice_ping();
+ return p;
+ }
+
+ private:
+ Ice::CommunicatorPtr ic;
+ };
+
+ class AutoUpdatePackages : public BaseScheduledTask {
+ public:
+ AutoUpdatePackages(Ice::CommunicatorPtr i) : BaseScheduledTask(i) { }
void runTimerTask() override {
- auto m = MaintenancePrx::checkedCast(ic->stringToProxy("maintenance"));
- m->ice_ping();
+ auto m = getProxy<MaintenancePrx>("maintenance");
auto rb = m->begin_refreshBugs();
m->updateRepositories();
m->refreshPackageTree();
m->sendNotifications();
m->end_refreshBugs(rb);
}
-
- private:
- Ice::CommunicatorPtr ic;
};
Maintenance::Maintenance(IceTray::DatabasePoolPtr d, Ice::CommunicatorPtr ic, Ice::PropertiesPtr p) :
Maintenance::Maintenance(d)
{
- if (auto sync = p->getPropertyAsIntWithDefault("GentooBrowseAPI.SyncTime", 0) * 60) {
- taskRunner = new IceUtil::Timer();
- taskRunner->scheduleRepeated(new AutoUpdatePackages(ic), IceUtil::Time::seconds(sync));
- }
+ addTask<AutoUpdatePackages>(ic, p, "SyncTime");
}
Maintenance::Maintenance(IceTray::DatabasePoolPtr d) :
@@ -48,6 +59,18 @@ namespace Gentoo {
}
}
+ template<typename Task>
+ void
+ Maintenance::addTask(Ice::CommunicatorPtr ic, Ice::PropertiesPtr p, const std::string & whenCfg)
+ {
+ if (auto sync = p->getPropertyAsIntWithDefault("GentooBrowseAPI." + whenCfg, 0) * 60) {
+ if (!taskRunner) {
+ taskRunner = new IceUtil::Timer();
+ }
+ taskRunner->scheduleRepeated(new Task(ic), IceUtil::Time::seconds(sync));
+ }
+ }
+
Ice::PropertiesPtr
Maintenance::properties(const Ice::Current & c)
{
diff --git a/gentoobrowse-api/service/maintenanceimpl.h b/gentoobrowse-api/service/maintenanceimpl.h
index 3a442b4..d28b1e6 100644
--- a/gentoobrowse-api/service/maintenanceimpl.h
+++ b/gentoobrowse-api/service/maintenanceimpl.h
@@ -30,6 +30,8 @@ namespace Gentoo {
void applyFileChanges(DB::Connection *, const boost::filesystem::path &, const Repository &, ChangeSet &) const;
private:
+ template<typename Task>
+ void addTask(Ice::CommunicatorPtr ic, Ice::PropertiesPtr p, const std::string & whenCfg);
static Ice::PropertiesPtr properties(const Ice::Current &);