7
7
using System . Linq ;
8
8
using System . Threading . Tasks ;
9
9
using Microsoft . Azure . WebJobs . Logging ;
10
+ using Microsoft . Azure . WebJobs . Script . Diagnostics ;
10
11
using Microsoft . Azure . WebJobs . Script . Eventing ;
11
12
using Microsoft . Extensions . Logging ;
12
13
@@ -18,17 +19,19 @@ internal abstract class WorkerProcess : IWorkerProcess, IDisposable
18
19
private readonly ILogger _workerProcessLogger ;
19
20
private readonly IWorkerConsoleLogSource _consoleLogSource ;
20
21
private readonly IScriptEventManager _eventManager ;
22
+ private readonly IMetricsLogger _metricsLogger ;
21
23
22
24
private Process _process ;
23
25
private bool _disposing ;
24
26
private Queue < string > _processStdErrDataQueue = new Queue < string > ( 3 ) ;
25
27
26
- internal WorkerProcess ( IScriptEventManager eventManager , IProcessRegistry processRegistry , ILogger workerProcessLogger , IWorkerConsoleLogSource consoleLogSource )
28
+ internal WorkerProcess ( IScriptEventManager eventManager , IProcessRegistry processRegistry , ILogger workerProcessLogger , IWorkerConsoleLogSource consoleLogSource , IMetricsLogger metricsLogger )
27
29
{
28
30
_processRegistry = processRegistry ;
29
31
_workerProcessLogger = workerProcessLogger ;
30
32
_consoleLogSource = consoleLogSource ;
31
33
_eventManager = eventManager ;
34
+ _metricsLogger = metricsLogger ;
32
35
}
33
36
34
37
public int Id => _process . Id ;
@@ -39,29 +42,32 @@ internal WorkerProcess(IScriptEventManager eventManager, IProcessRegistry proces
39
42
40
43
public Task StartProcessAsync ( )
41
44
{
42
- _process = CreateWorkerProcess ( ) ;
43
- try
45
+ using ( _metricsLogger . LatencyEvent ( MetricEventNames . ProcessStart ) )
44
46
{
45
- _process . ErrorDataReceived += ( sender , e ) => OnErrorDataReceived ( sender , e ) ;
46
- _process . OutputDataReceived += ( sender , e ) => OnOutputDataReceived ( sender , e ) ;
47
- _process . Exited += ( sender , e ) => OnProcessExited ( sender , e ) ;
48
- _process . EnableRaisingEvents = true ;
47
+ _process = CreateWorkerProcess ( ) ;
48
+ try
49
+ {
50
+ _process . ErrorDataReceived += ( sender , e ) => OnErrorDataReceived ( sender , e ) ;
51
+ _process . OutputDataReceived += ( sender , e ) => OnOutputDataReceived ( sender , e ) ;
52
+ _process . Exited += ( sender , e ) => OnProcessExited ( sender , e ) ;
53
+ _process . EnableRaisingEvents = true ;
49
54
50
- _workerProcessLogger ? . LogInformation ( $ "Starting worker process:{ _process . StartInfo . FileName } { _process . StartInfo . Arguments } ") ;
51
- _process . Start ( ) ;
52
- _workerProcessLogger ? . LogInformation ( $ "{ _process . StartInfo . FileName } process with Id={ _process . Id } started") ;
55
+ _workerProcessLogger ? . LogInformation ( $ "Starting worker process:{ _process . StartInfo . FileName } { _process . StartInfo . Arguments } ") ;
56
+ _process . Start ( ) ;
57
+ _workerProcessLogger ? . LogInformation ( $ "{ _process . StartInfo . FileName } process with Id={ _process . Id } started") ;
53
58
54
- _process . BeginErrorReadLine ( ) ;
55
- _process . BeginOutputReadLine ( ) ;
59
+ _process . BeginErrorReadLine ( ) ;
60
+ _process . BeginOutputReadLine ( ) ;
56
61
57
- // Register process only after it starts
58
- _processRegistry ? . Register ( _process ) ;
59
- return Task . CompletedTask ;
60
- }
61
- catch ( Exception ex )
62
- {
63
- _workerProcessLogger . LogError ( ex , "Failed to start Worker Channel" ) ;
64
- return Task . FromException ( ex ) ;
62
+ // Register process only after it starts
63
+ _processRegistry ? . Register ( _process ) ;
64
+ return Task . CompletedTask ;
65
+ }
66
+ catch ( Exception ex )
67
+ {
68
+ _workerProcessLogger . LogError ( ex , "Failed to start Worker Channel" ) ;
69
+ return Task . FromException ( ex ) ;
70
+ }
65
71
}
66
72
}
67
73
0 commit comments