添加下一周的定时任务

This commit is contained in:
zogodo
2020-03-08 18:51:44 +08:00
parent d7f14f8c6e
commit f2f1993611

View File

@@ -11,6 +11,7 @@
pTimedTask task_top = NULL; pTimedTask task_top = NULL;
int task_count = 0; int task_count = 0;
int day_sec = 86400;
bool AddTaskSingle(pTimedTask task) bool AddTaskSingle(pTimedTask task)
{ {
@@ -48,7 +49,6 @@ bool AddTaskSingle(pTimedTask task)
bool AddTaskWeek(pTimedTask task) bool AddTaskWeek(pTimedTask task)
{ {
int day_sec = 86400;
time_t now = time(NULL); time_t now = time(NULL);
int today_weekday = (now / day_sec + 3) % 7 + 1; //1970-01-01 星期五 int today_weekday = (now / day_sec + 3) % 7 + 1; //1970-01-01 星期五
int next_day = task->weekday - today_weekday; int next_day = task->weekday - today_weekday;
@@ -71,8 +71,16 @@ bool DelFirstTask()
{ {
pTimedTask tmp = task_top; pTimedTask tmp = task_top;
task_top = task_top->next; task_top = task_top->next;
free(tmp);
task_count--; task_count--;
if (tmp->weekday == 0)
{
free(tmp);
}
else
{
tmp->prs_time += 7 * day_sec;
AddTask(tmp);
}
return true; return true;
} }
return false; return false;
@@ -114,24 +122,12 @@ bool DelTask(int time)
return false; return false;
} }
void ProcessSingle()
{
UserRelaySet(task_top->socket_idx, task_top->on);
DelFirstTask();
}
void ProcessWeek()
{
//TODO 添加下一周的定时任务
ProcessSingle();
}
void ProcessTask() void ProcessTask()
{ {
task_log("process task time[%ld] socket_idx[%d] on[%d]", task_log("process task time[%ld] socket_idx[%d] on[%d]",
task_top->prs_time, task_top->socket_idx, task_top->on); task_top->prs_time, task_top->socket_idx, task_top->on);
if (task_top->weekday == 0) ProcessSingle(); UserRelaySet(task_top->socket_idx, task_top->on);
else ProcessWeek(); DelFirstTask();
} }
char* GetTaskStr() char* GetTaskStr()