0

I want to track long running operations on idHTTPServer from idHTTPClient by ping. How would I do that better way ? I need something unique for that. I tried with bind.id but with no success.

lets say i give something unique when thread is started it job

procedure TRPTests.SomeServerJob;
var
  jo: ISuperObject;
begin
  TThread.CreateAnonymousThread(
    procedure()
    begin
      Sleep(3000);
    end).Start();

  jo := SO();
  jo.S['BindId'] := Context.Binding.ID.ToString;
  FResponses.OkWithJson(jo.AsJSon(false, false));
end;

In some time later i want to check if job is done or what is progress? lets say i tried to do this that way

procedure TRPSystem.PingContext(aId: string);
var
  jo: ISuperObject;
  i: integer;
  r: boolean;
  someProgress: string;
begin
  with GetMain.Server.Contexts.LockList() do
  try
    for i := 0 to Count - 1 do
      if TIdContext(Items[i]).Binding.ID = aId.ToInteger then
      begin
        someProgress := '10 %';  // take progress param from my thread
        r := true;
        Break;
      end;
  finally
    GetMain.Server.Contexts.UnlockList();
  end;
  if r then
  begin
    jo := SO;
    jo.I['progress'] := someProgress;
    FResponses.OkWithJson(jo.AsJSon(false, false));
  end;
end;

Is that correct approach or better use another one ?

  • 2
    `TIdContext` simply represents a connected client connection, not any particular tasks. And `TIdSocketHandle` (used for the `TIdContext.Binding` property) does not have an `ID` property. You need to generate your own IDs manually, and keep track of them somewhere that you can access when needed. – Remy Lebeau Feb 02 '19 at 17:38
  • Hm... i thought there is smth in the lib itself )) So will do that manually. Thanks! – Stanislav Panteleev Feb 03 '19 at 05:33

0 Answers0