-
Notifications
You must be signed in to change notification settings - Fork 49
/
ZMQ.BrokerProtocol.pas
767 lines (651 loc) · 20.7 KB
/
ZMQ.BrokerProtocol.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
unit ZMQ.BrokerProtocol;
{ Base class for ZeroMQ brokers }
{$I Grijjy.inc}
interface
uses
Grijjy.Collections,
System.Generics.Collections,
System.Types,
System.SysUtils,
System.StrUtils,
System.DateUtils,
PascalZMQ,
ZMQ.Protocol,
ZMQ.Shared;
const
{ The millisecond interval for removing expired workers }
CLEANUP_INTERVAL = 5000;
type
TZMQBrokerProtocol = class;
TServices = class;
TService = class;
TWorkers = class;
{ Worker instance }
TWorker = class(TObject)
protected
FParent: TWorkers;
{ Hash id string for worker }
FWorkerId: String;
{ Routing frame for sending messages to worker }
FRoutingFrame: PZFrame;
{ Name of the service associated with this worker }
FService: String;
{ Last time a heartbeat was sent to this worker }
FLastHeartbeatSent: TDateTime;
{ Last time data was received from this worker }
FLastHeartbeatRecv: TDateTime;
{ Current system load of the worker }
FLoadAvg: Single;
private
{ Sends a message to the worker }
procedure Send(const ACommand: TZMQCommand; var AMsg: PZMessage);
{ Sends a heartbeat to the worker }
procedure SendHeartbeat;
{ Receives a heartbeat and the current load average of the worker
Load average represents the Unix /proc/loadavg result from the
shell which averages the current system load over a period of time.
We simulate this result on Windows since the primary platform for the
Worker will be Unix. }
procedure Heartbeat(const ALoadAvg: String);
{ Notifies the worker that the Broker is tracking the worker }
procedure SendReady;
{ Hash id string for worker }
property WorkerId: String read FWorkerId;
{ Name of the service associated with this worker }
property Service: String read FService write FService;
{ Last time a heartbeat was sent to this worker }
property LastHeartbeatSent: TDateTime read FLastHeartbeatSent write FLastHeartbeatSent;
{ Last time data was received from this worker }
property LastHeartbeatRecv: TDateTime read FLastHeartbeatRecv write FLastHeartbeatRecv;
{ Current system load of the worker }
property LoadAvg: Single read FLoadAvg;
public
constructor Create(const AParent: TWorkers; const AWorkerId: String;
const ARoutingFrame: PZFrame);
destructor Destroy; override;
end;
{ Workers class }
TWorkers = class(TObject)
protected
{ Internal }
FBroker: TZMQBrokerProtocol;
{ List of all active workers }
FWorkers: TObjectDictionary<String, TWorker>;
private
{ Adds a new worker to the active worker list along with the worker routing frame
and associates a service with the worker }
function Add(const AWorkerId: String; const ARoutingFrame: PZFrame;
const AService: String): TWorker;
{ Deletes a worker from the active worker list }
procedure Delete(const AWorkerId: String);
{ Sends a message to a worker }
procedure Send(const AWorkerId: String; const ACommand: TZMQCommand;
var AMsg: PZMessage);
{ Checks for heartbeat intervals and sends the heartbeat messages }
procedure SendHeartbeats;
{ Updates the load average statistics }
procedure Heartbeat(const AWorkerId: String; const ALoadAvg: String = '');
{ Called when a worker gracefully disconnects }
procedure Disconnect(const AWorkerId: String);
{ Returns the load average of the worker }
function LoadAvg(const AWorkerId: String): Single;
{ Notifies the worker that the Broker is tracking the worker }
procedure SendReady(const AWorkerId: String);
{ Protocol }
property Broker: TZMQBrokerProtocol read FBroker;
public
constructor Create(const ABroker: TZMQBrokerProtocol);
destructor Destroy; override;
end;
{ Service instance }
TService = class(TObject)
protected
FParent: TServices;
{ Name of the service }
FName: String;
{ List of workers for this service }
FWorkerIds: TgoSet<String>;
private
{ Adds a worker to the service }
procedure AddWorker(const AWorkerId: String);
{ Removes a worker from the service }
procedure DeleteWorker(const AWorkerId: String);
{ Finds the least used worker by load balancing }
function FindWorker: String;
{ Sends a message to the service. The service determines the appropriate worker
to service the message }
function Send(const ACommand: TZMQCommand; var AMsg: PZMessage;
const ASendToId: String = ''): Boolean;
public
constructor Create(const AParent: TServices; const AName: String);
destructor Destroy; override;
end;
{ Services class }
TServices = class(TObject)
protected
{ Internal }
FBroker: TZMQBrokerProtocol;
{ List of active services }
FServices: TObjectDictionary<String, TService>;
private
{ Adds a new service }
function Add(const AName: String): TService;
{ Adds a new worker to the service }
function AddWorker(const AName: String; const AWorkerId: String): Boolean;
{ Removes a worker from the service }
function DeleteWorker(const AName: String; const AWorkerId: String): Boolean;
{ Finds a worker in the service }
function FindWorker(const AName: String; out AWorkerId: String): Boolean;
{ Sends a message to the service. The service determines the appropriate worker
to service the message }
procedure Send(const AService: String; const ACommand: TZMQCommand;
var AMsg: PZMessage; const ASendToId: String = '');
{ Forwards message from a client to a worker without modification }
procedure ForwardClientMessageToWorker(const AService: String;
const ASentFrom: PZFrame; var AMsg: PZMessage; const ASendToId: String = '');
property Broker: TZMQBrokerProtocol read FBroker;
public
constructor Create(const ABroker: TZMQBrokerProtocol);
destructor Destroy; override;
end;
{ Broker interface }
TZMQBrokerProtocol = class(TZMQProtocol)
private
{ Services class }
FServices: TServices;
{ Workers class }
FWorkers: TWorkers;
{ Internal }
FLastCleanup: TDateTime;
protected
procedure DoIdle; override;
{ This method is called whenever a new message is received by the broker. }
procedure DoRecv(const ACommand: TZMQCommand; var AMsg: PZMessage;
var ASentFrom: PZFrame); override;
{ This event is fired whenever a new message is received from a client }
procedure DoRecvFromClient(const AService: String; const ASentFromId: String;
const ASentFrom: PZFrame; var AMsg: PZMessage; var AAction: TZMQAction; var ASendToId: String); virtual;
{ This event is fired whenever a new message is received from a worker }
procedure DoRecvFromWorker(const AService: String; const ASentFromId: String;
const ASentFrom: PZFrame; var AMsg: PZMessage; var AAction: TZMQAction); virtual;
{ This event is fired whenever a worker is deleted from a service }
procedure DoDeleteWorker(const AService: String; const AWorkerId: String); virtual;
public
constructor Create;
destructor Destroy; override;
{ Forward worker message to client }
procedure ForwardWorkerMessageToClient(const AService: String;
var AMsg: PZMessage);
{ Removes dead workers and cleans up related services }
procedure Cleanup;
{ Allocates a worker and returns the worker id }
function FindWorker(const AService: String; out AWorkerId: String): Boolean;
end;
implementation
{ TWorker }
constructor TWorker.Create(const AParent: TWorkers; const AWorkerId: String;
const ARoutingFrame: PZFrame);
begin
inherited Create;
FParent := AParent;
FWorkerId := AWorkerId;
FLastHeartbeatSent := Now;
FLastHeartbeatRecv := Now;
FLoadAvg := 0;
{ we make a copy of the routing frame for the worker because it is
destroyed automatically }
FRoutingFrame := ARoutingFrame.Clone;
end;
destructor TWorker.Destroy;
begin
FRoutingFrame.Free;
inherited;
end;
{ Sends a message to the worker }
procedure TWorker.Send(const ACommand: TZMQCommand;
var AMsg: PZMessage);
var
RoutingFrame: PZFrame;
begin
AMsg.PushEnum<TZMQCommand>(ACommand);
{ since we are sending the message to the worker, we must make a copy of the
workers routing frame because it will be destroyed along with the message
when the message is sent and we will need to use it again for subsequent
sends to the worker. }
RoutingFrame := FRoutingFrame.Clone;
FParent.Broker.Send(AMsg, RoutingFrame);
end;
{ Sends a heartbeat to the worker }
procedure TWorker.SendHeartbeat;
var
Msg: PZMessage;
begin
Msg := TZMessage.Create;
Send(TZMQCommand.Heartbeat, Msg);
FLastHeartbeatSent := Now;
end;
{ Receives a heartbeat and the current load average of the worker
Load average represents the Unix /proc/loadavg result from the
shell which averages the current system load over a period of time.
We simulate this result on Windows since the primary platform for the
Worker will be Unix. }
procedure TWorker.Heartbeat(const ALoadAvg: String);
var
StrArray: TStringDynArray;
begin
FLastHeartbeatRecv := Now;
if ALoadAvg <> '' then
begin
{ Load average over the recent past }
StrArray := SplitString(ALoadAvg, #32);
if Length(StrArray) > 0 then
FLoadAvg := StrToFloatDef(StrArray[0], -1);
end;
end;
{ Notifies the worker that the Broker is tracking the worker }
procedure TWorker.SendReady;
var
Msg: PZMessage;
begin
Msg := TZMessage.Create;
Msg.PushString(FWorkerId);
Send(TZMQCommand.Ready, Msg);
end;
{ TWorkers }
constructor TWorkers.Create(const ABroker: TZMQBrokerProtocol);
begin
inherited Create;
FBroker := ABroker;
FWorkers := TObjectDictionary<String, TWorker>.Create([doOwnsValues]);
end;
destructor TWorkers.Destroy;
begin
FWorkers.Free;
inherited;
end;
{ Adds a new worker to the active worker list along with the worker routing frame
and associates a service with the worker }
function TWorkers.Add(const AWorkerId: String; const ARoutingFrame: PZFrame;
const AService: String): TWorker;
begin
{ add worker if not already existing }
if not FWorkers.TryGetValue(AWorkerId, Result) then
begin
Result := TWorker.Create(Self, AWorkerId, ARoutingFrame);
FWorkers.Add(AWorkerId, Result);
Writeln(Format('Added worker %s', [AWorkerId]));
end;
{ keep track of service name }
Result.Service := AService;
end;
{ Deletes a worker from the active worker list }
procedure TWorkers.Delete(const AWorkerId: String);
begin
FWorkers.Remove(AWorkerId);
end;
{ Sends a message to a worker }
procedure TWorkers.Send(const AWorkerId: String; const ACommand: TZMQCommand;
var AMsg: PZMessage);
var
Worker: TWorker;
begin
if FWorkers.TryGetValue(AWorkerId, Worker) then
Worker.Send(ACommand, AMsg);
end;
{ Checks for heartbeat intervals and sends the heartbeat messages }
procedure TWorkers.SendHeartbeats;
var
Worker: TWorker;
begin
for Worker in FWorkers.Values do
begin
if MillisecondsBetween(Now, Worker.LastHeartbeatSent) > HEARTBEAT_INTERVAL then
Worker.SendHeartbeat;
end;
end;
{ Updates the last heartbeat received time from a worker }
procedure TWorkers.Heartbeat(const AWorkerId: String; const ALoadAvg: String);
var
Worker: TWorker;
begin
if FWorkers.TryGetValue(AWorkerId, Worker) then
Worker.Heartbeat(ALoadAvg);
end;
{ Called when a worker gracefully disconnects }
procedure TWorkers.Disconnect(const AWorkerId: String);
begin
{ nothing to do }
end;
{ Returns the load average of the worker }
function TWorkers.LoadAvg(const AWorkerId: String): Single;
var
Worker: TWorker;
begin
if FWorkers.TryGetValue(AWorkerId, Worker) then
Result := Worker.LoadAvg
else
Result := -1;
end;
{ Notifies the worker that the Broker is tracking the worker }
procedure TWorkers.SendReady(const AWorkerId: String);
var
Worker: TWorker;
begin
if FWorkers.TryGetValue(AWorkerId, Worker) then
Worker.SendReady;
end;
{ TService }
constructor TService.Create(const AParent: TServices; const AName: String);
begin
inherited Create;
FParent := AParent;
FName := AName;
FWorkerIds := TgoSet<String>.Create;
end;
destructor TService.Destroy;
begin
FWorkerIds.Free;
inherited;
end;
{ Adds a worker to the service }
procedure TService.AddWorker(const AWorkerId: String);
begin
FWorkerIds.AddOrSet(AWorkerId);
end;
{ Removes a worker from the service }
procedure TService.DeleteWorker(const AWorkerId: String);
begin
FWorkerIds.Remove(AWorkerId);
end;
{ Finds the least used worker by load balancing }
function TService.FindWorker: String;
var
WorkerId: String;
LoadAvg, LeastAvg: Single;
begin
LeastAvg := 999;
Result := '';
for WorkerId in FWorkerIds do
begin
LoadAvg := FParent.Broker.FWorkers.LoadAvg(WorkerId);
if LoadAvg >= 0 then
if LoadAvg < LeastAvg then
begin
LeastAvg := LoadAvg;
Result := WorkerId;
end
else
{ if more than one worker is equally least busy, then randomly select one }
if LoadAvg = LeastAvg then
begin
if (Random(2) = 1) then
begin
LeastAvg := LoadAvg;
Result := WorkerId;
end;
end
end;
end;
{ Sends a message to the service. The service determines the appropriate worker
to service the message }
function TService.Send(const ACommand: TZMQCommand; var AMsg: PZMessage;
const ASendToId: String = ''): Boolean;
var
WorkerId: String;
begin
Result := False;
if (FWorkerIds.Count > 0) then
begin
{ use specified worker, or find the least used worker }
if ASendToId = '' then
WorkerId := FindWorker
else
WorkerId := ASendToId;
{ send the message to the worker }
FParent.Broker.FWorkers.Send(WorkerId, ACommand, AMsg);
Result := True;
end;
end;
{ TServices }
constructor TServices.Create(const ABroker: TZMQBrokerProtocol);
begin
inherited Create;
FBroker := ABroker;
FServices := TObjectDictionary<String, TService>.Create([doOwnsValues]);
end;
destructor TServices.Destroy;
begin
FServices.Free;
inherited;
end;
{ Adds a new service }
function TServices.Add(const AName: String): TService;
begin
{ add service if not already existing }
if not FServices.TryGetValue(AName, Result) then
begin
Result := TService.Create(Self, AName);
FServices.Add(AName, Result);
Writeln(Format('Added service %s', [AName]));
end;
end;
{ Adds a new worker to the service }
function TServices.AddWorker(const AName: String; const AWorkerId: String): Boolean;
var
Service: TService;
begin
Result := False;
if FServices.TryGetValue(AName, Service) then
begin
if AWorkerId <> '' then
begin
Service.AddWorker(AWorkerId);
Result := True;
Writeln(Format('Added worker to service %s - %s', [AName, AWorkerId]));
end;
end;
end;
{ Removes a worker from the service }
function TServices.DeleteWorker(const AName: String; const AWorkerId: String): Boolean;
var
Service: TService;
begin
Result := False;
if FServices.TryGetValue(AName, Service) then
begin
if AWorkerId <> '' then
begin
Service.DeleteWorker(AWorkerId);
Result := True;
Writeln(Format('Deleted worker from service %s - %s', [AName, AWorkerId]));
end;
end;
end;
{ Finds a worker in the service }
function TServices.FindWorker(const AName: String; out AWorkerId: String): Boolean;
var
Service: TService;
begin
if FServices.TryGetValue(AName, Service) then
begin
AWorkerId := Service.FindWorker;
if AWorkerId <> '' then
Result := True
else
Result := False;
end
else
Result := False;
end;
{ Sends a message to the service. The service determines the appropriate worker
to service the message }
procedure TServices.Send(const AService: String; const ACommand: TZMQCommand;
var AMsg: PZMessage; const ASendToId: String = '');
var
Service: TService;
begin
{ add the service if it doesn't exist }
Service := Add(AService);
{ send the message to the service }
if Service <> nil then
begin
Service.Send(ACommand, AMsg, ASendToId);
end;
end;
{ Forwards message from a client to a worker without modification }
procedure TServices.ForwardClientMessageToWorker(const AService: String;
const ASentFrom: PZFrame; var AMsg: PZMessage; const ASendToId: String = '');
var
RoutingFrame: PZFrame;
begin
{ add the client reply routing frame, so the worker replies to
the correct client }
AMsg.PushEmptyFrame;
RoutingFrame := ASentFrom.Clone;
AMsg.Push(RoutingFrame);
{ send the message that was received from the client to a worker
that handles this service }
Send(AService, TZMQCommand.ClientMessage, AMsg, ASendToId);
end;
{ TZMQBrokerProtocol }
constructor TZMQBrokerProtocol.Create;
begin
inherited Create; { broker object is not thread safe, so do not use the zmq thread pool! }
{ Initialize }
FServices := TServices.Create(Self);
FWorkers := TWorkers.Create(Self);
FLastCleanup := Now;
end;
destructor TZMQBrokerProtocol.Destroy;
begin
inherited;
FWorkers.Free;
FServices.Free;
end;
{ Forward worker message to client }
procedure TZMQBrokerProtocol.ForwardWorkerMessageToClient(const AService: String;
var AMsg: PZMessage);
var
RoutingFrame: PZFrame;
begin
{ the client routing frame is embedded into the message as it is sent from the
broker to the worker and back. We extract it here and use it to direct
the message to the correct client }
RoutingFrame := AMsg.Unwrap;
try
AMsg.PushString(AService);
AMsg.PushEnum<TZMQCommand>(TZMQCommand.ClientMessage);
Send(AMsg, RoutingFrame);
finally
RoutingFrame.Free;
end;
end;
{ This method is called when recv is idle, so that the parent can
perform other background tasks while connected }
procedure TZMQBrokerProtocol.DoIdle;
begin
{ send heartbeat to workers }
FWorkers.SendHeartbeats;
{ remove expired workers }
if MillisecondsBetween(Now, FLastCleanup) > CLEANUP_INTERVAL then
Cleanup;
end;
{ This event is fired whenever a new message is received by the broker. }
procedure TZMQBrokerProtocol.DoRecv(const ACommand: TZMQCommand; var AMsg: PZMessage;
var ASentFrom: PZFrame);
var
SentFromId: String;
Service: String;
LoadAvg: String;
SendToId: String;
Action: TZMQAction;
begin
inherited;
SentFromId := ASentFrom.ToHexString;
Service := AMsg.PopString;
case ACommand of
TZMQCommand.Ready:
begin
{ add worker }
FWorkers.Add(
SentFromId,
ASentFrom, // worker routing frame
Service);
{ add service }
FServices.Add(Service);
{ add worker to the service }
FServices.AddWorker(Service, SentFromId);
{ notify the worker }
FWorkers.SendReady(SentFromId);
end;
TZMQCommand.Heartbeat:
begin
LoadAvg := AMsg.PopString;
FWorkers.Heartbeat(SentFromId, LoadAvg);
end;
TZMQCommand.Disconnect:
begin
FWorkers.Disconnect(SentFromId);
end;
TZMQCommand.ClientMessage:
begin
Action := TZMQAction.Discard;
DoRecvFromClient(Service, SentFromId, ASentFrom, AMsg, Action, SendToId);
case Action of
TZMQAction.Discard: ;
TZMQAction.Forward: FServices.ForwardClientMessageToWorker(Service, ASentFrom, AMsg);
TZMQAction.SendTo: FServices.ForwardClientMessageToWorker(Service, ASentFrom, AMsg, SendToId);
end;
end;
TZMQCommand.WorkerMessage:
begin
FWorkers.Heartbeat(SentFromId); { any data recv }
Action := TZMQAction.Discard;
DoRecvFromWorker(Service, SentFromId, ASentFrom, AMsg, Action);
case Action of
TZMQAction.Discard: ;
TZMQAction.Forward: ForwardWorkerMessageToClient(Service, AMsg);
end;
end;
end;
end;
procedure TZMQBrokerProtocol.DoRecvFromClient(const AService: String; const ASentFromId: String;
const ASentFrom: PZFrame; var AMsg: PZMessage; var AAction: TZMQAction; var ASendToId: String);
begin
inherited;
end;
procedure TZMQBrokerProtocol.DoRecvFromWorker(const AService: String; const ASentFromId: String;
const ASentFrom: PZFrame; var AMsg: PZMessage; var AAction: TZMQAction);
begin
inherited;
end;
procedure TZMQBrokerProtocol.DoDeleteWorker(const AService: String; const AWorkerId: String);
begin
inherited;
end;
function TZMQBrokerProtocol.FindWorker(const AService: String; out AWorkerId: String): Boolean;
begin
Result := FServices.FindWorker(AService, AWorkerId);
end;
{ Removes dead workers and cleans up related services }
procedure TZMQBrokerProtocol.Cleanup;
var
Worker: TWorker;
WorkerId: String;
Service: String;
begin
for Worker in FWorkers.FWorkers.Values.ToArray do
if MillisecondsBetween(Now, Worker.LastHeartbeatRecv) > HEARTBEAT_EXPIRES then
begin
WorkerId := Worker.WorkerId;
Service := Worker.Service;
{ remove worker from service }
FServices.DeleteWorker(Service, WorkerId);
{ remove from workers list }
FWorkers.Delete(WorkerId);
{ raise an event to indicate that we have lost a worker }
DoDeleteWorker(Service, WorkerId);
end;
FLastCleanup := Now;
end;
end.