mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-30 17:25:26 +02:00
[Windows Agent] Avoid execute module at first time if is out cron
This commit is contained in:
parent
611652820c
commit
5a3e4e1599
@ -232,6 +232,22 @@ bool Cron::shouldExecuteAt (time_t date) {
|
||||
return this->utimestamp < date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if a module should be executed when utimestamp is not calculated yet
|
||||
*
|
||||
* @param date Current date
|
||||
* @return true It is not first time and current date fit in cron
|
||||
* @return false Don't execute first time
|
||||
*/
|
||||
bool Cron::shouldExecuteAtFirst (time_t date) {
|
||||
|
||||
// Return true if it is not first
|
||||
if (this->utimestamp != 0) return true;
|
||||
|
||||
// Check current date in cron
|
||||
return isInCron(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update the cron utimestamp
|
||||
*
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* Pandora cron manager for Win32.
|
||||
|
||||
Copyright (C) 2016 Artica ST.
|
||||
Written by Ramon Novoa.
|
||||
Copyright (C) 2018 Artica ST.
|
||||
Written by Fermin Hernandez.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -72,6 +72,7 @@ class Cron {
|
||||
// Other methods
|
||||
void update(time_t date, int interval);
|
||||
bool shouldExecuteAt(time_t date);
|
||||
bool shouldExecuteAtFirst(time_t date);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1578,9 +1578,12 @@ Pandora_Module::checkCron (int interval) {
|
||||
time_t now = time(NULL);
|
||||
if (!this->cron->shouldExecuteAt(now)) return false;
|
||||
|
||||
// Check if should execute this module at first before update cron params
|
||||
bool execute = this->cron->shouldExecuteAtFirst(now);
|
||||
|
||||
this->cron->update(now, interval);
|
||||
|
||||
return true;
|
||||
return execute;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user