martinzink commented on code in PR #1335:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1335#discussion_r882754960
##########
libminifi/src/CronDrivenSchedulingAgent.cpp:
##########
@@ -20,66 +20,56 @@
#include "CronDrivenSchedulingAgent.h"
#include <chrono>
#include <memory>
-#include <thread>
-#include <iostream>
#include "core/Processor.h"
#include "core/ProcessContext.h"
#include "core/ProcessSessionFactory.h"
-#include "core/Property.h"
using namespace std::literals::chrono_literals;
+using std::chrono::ceil;
+using std::chrono::seconds;
+using std::chrono::milliseconds;
+using std::chrono::time_point_cast;
+using std::chrono::system_clock;
-namespace org {
-namespace apache {
-namespace nifi {
-namespace minifi {
+namespace org::apache::nifi::minifi {
-utils::TaskRescheduleInfo CronDrivenSchedulingAgent::run(core::Processor*
processor, const std::shared_ptr<core::ProcessContext> &processContext,
- const
std::shared_ptr<core::ProcessSessionFactory> &sessionFactory) {
+utils::TaskRescheduleInfo CronDrivenSchedulingAgent::run(core::Processor*
processor,
+ const
std::shared_ptr<core::ProcessContext>& processContext,
+ const
std::shared_ptr<core::ProcessSessionFactory>& sessionFactory) {
if (this->running_ && processor->isRunning()) {
auto uuid = processor->getUUID();
- std::chrono::system_clock::time_point result;
- std::chrono::system_clock::time_point from =
std::chrono::system_clock::now();
- {
- std::lock_guard<std::mutex> locK(mutex_);
+ auto current_time = date::make_zoned<seconds>(date::current_zone(),
time_point_cast<seconds>(system_clock::now()));
+ std::lock_guard<std::mutex> lock(mutex_);
- auto sched_f = schedules_.find(uuid);
- if (sched_f != std::end(schedules_)) {
- result = last_exec_[uuid];
- if (from >= result) {
- result = sched_f->second.cron_to_next(from);
- last_exec_[uuid] = result;
- } else {
- // we may be woken up a little early so that we can honor our time.
- // in this case we can return the next time to run with the
expectation
- // that the wakeup mechanism gets more granular.
- return
utils::TaskRescheduleInfo::RetryIn(std::chrono::duration_cast<std::chrono::milliseconds>(result
- from));
- }
- } else {
- Bosma::Cron schedule(processor->getCronPeriod());
- result = schedule.cron_to_next(from);
- last_exec_[uuid] = result;
- schedules_.insert(std::make_pair(uuid, schedule));
- }
- }
+ if (!schedules_.contains(uuid))
+ schedules_.insert(std::make_pair(uuid,
utils::Cron(processor->getCronPeriod())));
+
+ if (!last_exec_.contains(uuid))
+ last_exec_.insert(std::make_pair(uuid, current_time.get_local_time()));
Review Comment:
Agree it looks better I've added your second suggestion in
https://github.com/apache/nifi-minifi-cpp/pull/1335/commits/1745a0dff6c4420d34b8bdbaf3f76a8d18e7fde0#
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]