From 3ff800122096a3343fab07da169704efc7a2cb6a Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 26 Oct 2022 16:34:27 +0200 Subject: [PATCH] . --- .idea/workspace.xml | 21 +++++++++++---------- scripts/lib/ical.php | 1 - scripts/lib/redis.php | 10 ++++++++-- scripts/lib/switchbot.php | 4 ++-- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 8efa664..2534e78 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,8 +3,8 @@ - + diff --git a/scripts/lib/ical.php b/scripts/lib/ical.php index aa02e9b..3adf328 100644 --- a/scripts/lib/ical.php +++ b/scripts/lib/ical.php @@ -30,7 +30,6 @@ function searchIcalEvent($cal, $start = null, $end = null) $client = icalClient(); $client->SetCalendar($calendarBase . '/' . trim($cal, '/') . '/'); - $events = $client->GetEvents(getIcalTimestamp($start), getIcalTimestamp($end)); $res = []; foreach ($events as $event) { diff --git a/scripts/lib/redis.php b/scripts/lib/redis.php index bb0406f..f56cb2b 100644 --- a/scripts/lib/redis.php +++ b/scripts/lib/redis.php @@ -112,15 +112,21 @@ function redisEventListener($channel, $callback) * @param $closure Closure * @return mixed */ -function remember($key, $ttl, $closure) +function remember($key, $ttl, $closure, $default = null) { + $rememberSaveKey = $key . '_save_remember'; $client = getRedisClient(); if (!$client->exists($key)) { - $data = call_user_func($closure); + try { + $data = call_user_func($closure); + } catch (Exception $e) { + $data = getState($rememberSaveKey, $default); + } $client->set($key, $data); $client->expire($key, $ttl); } else { $data = $client->get($key); } + setState($rememberSaveKey, $data); return $data; } diff --git a/scripts/lib/switchbot.php b/scripts/lib/switchbot.php index 16ad573..2a4ddc4 100644 --- a/scripts/lib/switchbot.php +++ b/scripts/lib/switchbot.php @@ -98,7 +98,7 @@ function isVincent() { return remember('vincent_in_paris', 3600, function () { return _isVincent(); - }); + }, true); } function _isVincent() @@ -117,7 +117,7 @@ function isJerome() { return remember('jerome_in_paris', 3600, function () { return _isJerome(); - }); + }, true); } function _isJerome() -- 2.39.5