Simplify next execution detection
This commit is contained in:
parent
cd77ad9d68
commit
501d92bf6b
|
|
@ -148,19 +148,18 @@ class Programmation:
|
|||
def get_next_execution(self, from_date=None, *args, **kwargs):
|
||||
from_date = datetime.now() if from_date is None else from_date
|
||||
|
||||
next_iteration = None
|
||||
if self.recording_start_date is not None:
|
||||
next_iteration = self.recording_start_date
|
||||
return self.recording_start_date
|
||||
|
||||
if self.recurrence_cron is not None:
|
||||
cron = CronSim(self.recurrence_cron, from_date - timedelta(minutes=1))
|
||||
if self.recurrence_start_date is not None and self.recurrence_start_date > from_date:
|
||||
start_date = self.recurrence_start_date
|
||||
else:
|
||||
start_date = from_date
|
||||
|
||||
next_iteration = next(cron)
|
||||
return next(CronSim(self.recurrence_cron, start_date - timedelta(minutes=1)))
|
||||
|
||||
while next_iteration < self.recurrence_start_date:
|
||||
next_iteration = next(cron)
|
||||
|
||||
return next_iteration
|
||||
return None
|
||||
|
||||
def set_id(self, id=None):
|
||||
self.id = id
|
||||
|
|
|
|||
|
|
@ -602,6 +602,23 @@ class TestProgrammation(unittest.TestCase):
|
|||
self.assertIsNotNone(self.pm.delete_programmation_by_id(id=self.last_added_id))
|
||||
self.assertEqual(6, len(self.pm.get_all_enabled_programmations()))
|
||||
|
||||
prog = Programmation(programmation=(
|
||||
{
|
||||
'url': "a valid url",
|
||||
'planning': {
|
||||
'recurrence_cron': '00 00 * * *',
|
||||
'recurrence_start_date': '2022-12-01 00:00',
|
||||
},
|
||||
}
|
||||
))
|
||||
|
||||
self.assertEqual(datetime.fromisoformat('2022-12-01 00:00:00'),
|
||||
prog.get_next_execution(from_date=datetime.fromisoformat('2022-11-30 12:00')))
|
||||
self.assertEqual(datetime.fromisoformat('2022-12-01 00:00:00'),
|
||||
prog.get_next_execution(from_date=datetime.fromisoformat('2022-12-01 00:00')))
|
||||
self.assertEqual(datetime.fromisoformat('2022-12-02 00:00:00'),
|
||||
prog.get_next_execution(from_date=datetime.fromisoformat('2022-12-01 00:01')))
|
||||
|
||||
def test_end_dates_manipulation(self):
|
||||
self.assertEqual(datetime.fromisoformat('2022-12-01 02:00'), Programmation(programmation={
|
||||
'url': "a valid url",
|
||||
|
|
|
|||
Loading…
Reference in New Issue