mirror of
https://github.com/PerMalmberg/libcron.git
synced 2025-04-22 08:23:04 -05:00
Handles jumps of >=3h
This commit is contained in:
parent
e99b049d2b
commit
97a0a5a9c2
@ -114,7 +114,7 @@ namespace libcron
|
|||||||
{
|
{
|
||||||
first_tick = false;
|
first_tick = false;
|
||||||
}
|
}
|
||||||
else if (now - last_tick < hours{3})
|
else if (now > last_tick && now - last_tick <= hours{3})
|
||||||
{
|
{
|
||||||
// Reschedule all tasks.
|
// Reschedule all tasks.
|
||||||
for (auto& t : tasks.get_tasks())
|
for (auto& t : tasks.get_tasks())
|
||||||
@ -122,7 +122,7 @@ namespace libcron
|
|||||||
t.calculate_next(now);
|
t.calculate_next(now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(now < last_tick && now >= last_tick - hours{3})
|
else if(now < last_tick && now - last_tick < hours{3})
|
||||||
{
|
{
|
||||||
// Prevent tasks from running until the clock has reached current 'last_tick'.
|
// Prevent tasks from running until the clock has reached current 'last_tick'.
|
||||||
for (auto& t : tasks.get_tasks())
|
for (auto& t : tasks.get_tasks())
|
||||||
|
@ -248,7 +248,7 @@ SCENARIO("Clock changes")
|
|||||||
REQUIRE(c.tick() == 1);
|
REQUIRE(c.tick() == 1);
|
||||||
REQUIRE(c.tick() == 0);
|
REQUIRE(c.tick() == 0);
|
||||||
REQUIRE(c.tick() == 0);
|
REQUIRE(c.tick() == 0);
|
||||||
clock.add(minutes{30}); // 01:30
|
clock.add(minutes{30}); // 01:30
|
||||||
REQUIRE(c.tick() == 0);
|
REQUIRE(c.tick() == 0);
|
||||||
clock.add(minutes{15}); // 01:45
|
clock.add(minutes{15}); // 01:45
|
||||||
REQUIRE(c.tick() == 0);
|
REQUIRE(c.tick() == 0);
|
||||||
@ -261,16 +261,16 @@ SCENARIO("Clock changes")
|
|||||||
THEN("Task are rescheduled, not run")
|
THEN("Task are rescheduled, not run")
|
||||||
{
|
{
|
||||||
REQUIRE(c.tick() == 1);
|
REQUIRE(c.tick() == 1);
|
||||||
std::cout << c << std::endl;
|
std::cout << "0: " << c << std::endl;
|
||||||
clock.add(hours{3}); // 03:00
|
clock.add(hours{3}); // 03:00
|
||||||
REQUIRE(c.tick() == 1); // Rescheduled
|
REQUIRE(c.tick() == 1); // Rescheduled
|
||||||
std::cout << c << std::endl;
|
std::cout << "1: " << c << std::endl;
|
||||||
clock.add(minutes{15}); // 03:15
|
clock.add(minutes{15}); // 03:15
|
||||||
REQUIRE(c.tick() == 1);
|
REQUIRE(c.tick() == 0);
|
||||||
std::cout << c << std::endl;
|
std::cout << "2: " << c << std::endl;
|
||||||
clock.add(minutes{45}); // 04:00
|
clock.add(minutes{45}); // 04:00
|
||||||
REQUIRE(c.tick() == 1);
|
REQUIRE(c.tick() == 1);
|
||||||
std::cout << c << std::endl;
|
std::cout << "3: " << c << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user