Jump to content

UniTimer


picyka

Recommended Posts

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?

Link to comment
Share on other sites

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.

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...