diff --git a/src/views/AuthApp.jsx b/src/views/AuthApp.jsx index 66054c3..1e391e4 100644 --- a/src/views/AuthApp.jsx +++ b/src/views/AuthApp.jsx @@ -70,6 +70,7 @@ function AuthApp() { } return () => { disconnectWebsocket() + fetchEmailWorker.postMessage({ command: 'logout' }) if (_fetchEmailWorker) { _fetchEmailWorker.terminate(); } diff --git a/src/workers/fetchEmailWorker.js b/src/workers/fetchEmailWorker.js index 24ea289..3fc32c4 100644 --- a/src/workers/fetchEmailWorker.js +++ b/src/workers/fetchEmailWorker.js @@ -1,5 +1,6 @@ import { getEmailFetchAction } from './../actions/EmailActions' +let timeoutID; self.onmessage = (event) => { if (event.data.command === 'fetchEmail') { // Get the parameter @@ -7,9 +8,24 @@ self.onmessage = (event) => { console.log('Worker: Received command `fetchEmail` with param:', param) // Do something...... - setInterval(() => { - getEmailFetchAction(param) - }, 10 * 1000) // prod: 30 minutes + const fetchEmails = () => { + try { + getEmailFetchAction(param); + } catch (error) {} + timeoutID = setTimeout(fetchEmails, 10 * 1000); // prod: 30 minutes + }; + + // Start fetching emails + fetchEmails(); + // intervalID = setInterval(() => { + // getEmailFetchAction(param) + // }, 10 * 1000) // prod: 30 minutes + // getEmailFetchAction(param) + } + if (event.data.command === 'logout') { + console.log('logout') + // clearInterval(intervalID) + clearTimeout(timeoutID) } } self.onerror = function (error) {