@@ -84,7 +84,7 @@ void PeriodicTask::SetSettings(Settings settings) {
8484 {
8585 auto writer = settings_.StartWrite ();
8686 settings.flags = writer->flags ;
87- has_changed = settings.period != writer->period ;
87+ has_changed = settings.period != writer->period || settings. enabled != writer-> enabled ;
8888 *writer = std::move (settings);
8989 writer.Commit ();
9090 }
@@ -99,6 +99,10 @@ void PeriodicTask::SetSettings(Settings settings) {
9999
100100void PeriodicTask::ForceStepAsync () {
101101 should_force_step_ = true ;
102+ if (!writer->enabled ) {
103+ writer->enabled = true ;
104+ writer.Commit ();
105+ }
102106 changed_event_.Send ();
103107}
104108
@@ -125,11 +129,12 @@ void PeriodicTask::Run() {
125129 const auto before = std::chrono::steady_clock::now ();
126130 bool no_exception = true ;
127131
128- if (!std::exchange (skip_step, false )) {
132+ const auto settings = settings_.Read ();
133+ bool taskEnabled = settings->enabled ;
134+ if (!std::exchange (skip_step, false ) && taskEnabled) {
129135 no_exception = Step ();
130136 }
131137
132- const auto settings = settings_.Read ();
133138 auto period = settings->period ;
134139 const auto exception_period = settings->exception_period .value_or (period);
135140
@@ -142,12 +147,16 @@ void PeriodicTask::Run() {
142147 start = std::chrono::steady_clock::now ();
143148 }
144149
145- while (changed_event_.WaitForEventUntil (start + MutatePeriod (period))) {
150+ while ((!taskEnabled && changed_event_.WaitForEvent ()) || (taskEnabled && changed_event_. WaitForEventUntil (start + MutatePeriod (period) ))) {
146151 if (should_force_step_.exchange (false )) {
147152 break ;
148153 }
149154 // The config variable value has been changed, reload
150155 const auto settings = settings_.Read ();
156+ taskEnabled = settings->enabled ;
157+ if (!taskEnabled) {
158+ break ;
159+ }
151160 period = settings->period ;
152161 const auto exception_period = settings->exception_period .value_or (period);
153162 if (!no_exception) period = exception_period;
0 commit comments