cron expression validation and error reports
This commit is contained in:
parent
1612c0a830
commit
21c63bcadd
|
|
@ -28,6 +28,7 @@ timarr = [
|
|||
~crontmr(14)~,
|
||||
~crontmr(15)~
|
||||
];
|
||||
function showcronerr(err) {if(err != "") alert(err);}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
@ -51,8 +52,9 @@ timarr = [
|
|||
</section>
|
||||
</main>
|
||||
<script>
|
||||
drawtimers(timarr);
|
||||
drawtimers(timarr);
|
||||
showMenu('header-toggle','navbar');
|
||||
showcronerr("~cronerr~");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -248,3 +248,4 @@ function drawtimers(tarr) {
|
|||
target.innerHTML = content;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 6785ad092344b6c391fa24b0a0b25ffd258d79e6
|
||||
Subproject commit e6cb1512fd3fb4fdb07ee1132d625f861331447d
|
||||
|
|
@ -42,6 +42,7 @@
|
|||
#define CRON_TIMERS_NUMBER (16)
|
||||
#define TIMER_NAME_LENGTH (16)
|
||||
#define TIMER_CRONSTRING_LENGTH (32)
|
||||
#define CRON_EXPRESS_MAX_LENGTH (128)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,9 +24,10 @@
|
|||
#include "esp_err.h"
|
||||
#include "cron.h"
|
||||
#include "jobs.h"
|
||||
|
||||
#include "ccronexpr.h"
|
||||
|
||||
esp_err_t InitCronSheduler();
|
||||
esp_err_t ReloadCronSheduler();
|
||||
char* GetCronError();
|
||||
|
||||
#endif /* MAIN_INCLUDE_CRONTIMERS_H_ */
|
||||
|
|
|
|||
|
|
@ -26,6 +26,12 @@
|
|||
#define TAG "CRON_TIMER"
|
||||
|
||||
static cron_job *JobsList[CRON_TIMERS_NUMBER];
|
||||
static char cron_express_error[CRON_EXPRESS_MAX_LENGTH];
|
||||
|
||||
char* GetCronError()
|
||||
{
|
||||
return cron_express_error;
|
||||
}
|
||||
|
||||
void custom_cron_job_callback(cron_job *job)
|
||||
{
|
||||
|
|
@ -43,20 +49,39 @@ esp_err_t InitCronSheduler()
|
|||
return res;
|
||||
}
|
||||
|
||||
|
||||
const char* check_expr(const char* expr) {
|
||||
const char* err = NULL;
|
||||
cron_expr test;
|
||||
memset(&test, 0, sizeof(test));
|
||||
cron_parse_expr(expr, &test, &err);
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t ReloadCronSheduler()
|
||||
{
|
||||
//remove all jobs
|
||||
ESP_LOGI(TAG,"Cron stop call result %d",cron_stop());
|
||||
cron_job_clear_all();
|
||||
//check if we have jobs to run
|
||||
bool isExpressError = false;
|
||||
for (int i = 0; i < CRON_TIMERS_NUMBER; i++)
|
||||
{
|
||||
if (!GetAppConf()->Timers[i].del && GetAppConf()->Timers[i].enab)
|
||||
const char* err = check_expr(GetAppConf()->Timers[i].cron);
|
||||
if(err)
|
||||
{
|
||||
snprintf (cron_express_error, CRON_EXPRESS_MAX_LENGTH-1, "In timer %d expression error:%s", i+1, err);
|
||||
ESP_LOGE(TAG, "%s", cron_express_error);
|
||||
isExpressError = true;
|
||||
continue;
|
||||
}
|
||||
else if (!GetAppConf()->Timers[i].del && GetAppConf()->Timers[i].enab)
|
||||
{
|
||||
JobsList[i] = cron_job_create(GetAppConf()->Timers[i].cron, custom_cron_job_callback,
|
||||
(void*) &GetAppConf()->Timers[i]);
|
||||
}
|
||||
}
|
||||
if(!isExpressError) cron_express_error[0] = 0x00; //clear last cron expression parse
|
||||
int jobs_num = cron_job_node_count();
|
||||
ESP_LOGI(TAG, "In config presents %d jobs", jobs_num);
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include "webguiapp.h"
|
||||
#include "jWrite.h"
|
||||
#include "AppConfiguration.h"
|
||||
#include "CronTimers.h"
|
||||
|
||||
static void HTTPPrint_crontmr(char *VarData, void *arg)
|
||||
{
|
||||
|
|
@ -46,6 +47,11 @@ static void HTTPPrint_crontmr(char *VarData, void *arg)
|
|||
}
|
||||
}
|
||||
|
||||
static void HTTPPrint_cronerr(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, GetCronError());
|
||||
}
|
||||
|
||||
//Default string if not found handler
|
||||
static void HTTPPrint_DEF(char *VarData, void *arg)
|
||||
{
|
||||
|
|
@ -60,6 +66,7 @@ static void HTTPPrint_status_fail(char *VarData, void *arg)
|
|||
dyn_var_handler_t HANDLERS_ARRAY_CUST[] = {
|
||||
|
||||
{ "crontmr", sizeof("crontmr") - 1, &HTTPPrint_crontmr },
|
||||
{ "cronerr", sizeof("cronerr") - 1, &HTTPPrint_cronerr },
|
||||
/*ERROR report*/
|
||||
{ "status_fail", sizeof("status_fail") - 1, &HTTPPrint_status_fail },
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user