Merge "Make cron-triggers not play catchup"

This commit is contained in:
Zuul 2018-06-18 16:03:03 +00:00 committed by Gerrit Code Review
commit 846222cf2f
2 changed files with 12 additions and 1 deletions

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import json
from oslo_config import cfg
@ -121,9 +122,11 @@ def advance_cron_trigger(t):
delete_trust=False
)
else: # if remaining execution = None or > 0.
# In case the we are lagging or if the api stopped for some time
# we use the max of the current time or the next scheduled time.
next_time = triggers.get_next_execution_time(
t.pattern,
t.next_execution_time
max(datetime.datetime.utcnow(), t.next_execution_time)
)
# Update the cron trigger with next execution details

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import time
import mock
from oslo_config import cfg
@ -120,7 +121,9 @@ class ProcessCronTriggerTest(base.EngineTestCase):
next_trigger = next_triggers[0]
next_execution_time_before = next_trigger.next_execution_time
ts_before = datetime.datetime.utcnow()
time.sleep(1) # this is to simulate lagging
periodic.process_cron_triggers_v2(None, None)
next_triggers = triggers.get_next_cron_triggers()
@ -130,6 +133,11 @@ class ProcessCronTriggerTest(base.EngineTestCase):
next_trigger = next_triggers[0]
next_execution_time_after = next_trigger.next_execution_time
self.assertGreater(
next_execution_time_after,
ts_before
)
self.assertNotEqual(
next_execution_time_before,
next_execution_time_after