picyka Posted March 30, 2023 Share Posted March 30, 2023 I have a team that checks every 5 minutes to see if there is any task to display on the screen. These timers are dangerous to use because the session may not expire. Is there any way to take care of this? Another situation, the ChainMode property from my research, this option checked only runs the timer if there is no event being processed, would that be it? Would it be good to use it in these situations? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted March 30, 2023 Share Posted March 30, 2023 6 minutes ago, picyka said: These timers are dangerous to use because the session may not expire. 1. Try to use UniThreadTimer on Server side 2. You can add extra functions to check if user is online and if is not then close session : Quote Link to comment Share on other sites More sharing options...
picyka Posted March 30, 2023 Author Share Posted March 30, 2023 2 hours ago, irigsoft said: 1. Try to use UniThreadTimer on Server side 2. You can add extra functions to check if user is online and if is not then close session : @Sherzod Do you have any tips for this? Quote Link to comment Share on other sites More sharing options...
picyka Posted March 31, 2023 Author Share Posted March 31, 2023 function hasTask(host, token) { try { var Http = new XMLHttpRequest(); Http.open("GET", host, false); Http.setRequestHeader('Authorization', 'Bearer ' + token); Http.send(); if (Http.status == 200) { console.log('Buscado tarefa...'); if (Http.responseText.includes("true")) { top.ajaxRequest(top.MainForm.form, '_task', ['value=true']); } } } catch (err) { console.log('Erro Tarefa:' + err); } }; procedure TUniMainModule.ExecuteTimerTarefa; begin {180000 - 3 MINUTOS} try var lUrl := Self.URL_EX_API + 'END POINT'; var lJsString := 'var TimerTarefa = setInterval(function () {hasTask(' + QuotedStr(lUrl) + ',' + QuotedStr(Self.TOKEN_API) + ');}, 180000);'; UniSession.JSCode(lJsString); except on E: Exception do TMessageUtils.Error(E.Message); end; procedure TMainForm.UniFormAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if SameStr(EventName, '_task') then begin TToastUtils.Aviso('Tarefa encontrada, ja vou te mostrar!', False, 'Aviso de Tarefa',8000); UniTimerTarefas.Enabled := True; end; end; I will post here my solution, as I use API it became easier to solve. Ajax only fires when it's really needed. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.