@@ -2,57 +2,48 @@ namespace OJS.Servers.Worker.Consumers;
2
2
3
3
using MassTransit ;
4
4
using Microsoft . Extensions . Logging ;
5
+ using Microsoft . Extensions . Options ;
5
6
using OJS . Services . Common ;
6
7
using OJS . Services . Worker . Business ;
7
8
using OJS . Services . Infrastructure . Extensions ;
8
9
using System ;
9
10
using System . Threading . Tasks ;
10
11
using OJS . PubSub . Worker . Models . Submissions ;
11
12
using OJS . Services . Common . Extensions ;
12
- using OJS . Services . Common . Models . Submissions ;
13
13
using OJS . Services . Common . Models . Submissions . ExecutionContext ;
14
14
using OJS . Services . Infrastructure ;
15
15
using OJS . Services . Infrastructure . Constants ;
16
+ using OJS . Services . Worker . Models . Configuration ;
16
17
using OJS . Workers . Common . Exceptions ;
18
+ using OJS . Workers . Common . Helpers ;
17
19
using OJS . Workers . Common . Models ;
18
20
using ConfigurationException = OJS . Workers . Common . Exceptions . ConfigurationException ;
19
21
20
- public class SubmissionsForProcessingConsumer : IConsumer < SubmissionForProcessingPubSubModel >
22
+ public class SubmissionsForProcessingConsumer (
23
+ ISubmissionsBusinessService submissionsBusiness ,
24
+ IPublisherService publisher ,
25
+ IHostInfoService hostInfoService ,
26
+ ILogger < SubmissionsForProcessingConsumer > logger ,
27
+ IDatesService dates ,
28
+ IOptions < SubmissionExecutionConfig > executionConfigAccessor )
29
+ : IConsumer < SubmissionForProcessingPubSubModel >
21
30
{
22
- private readonly ISubmissionsBusinessService submissionsBusiness ;
23
- private readonly IPublisherService publisher ;
24
- private readonly IHostInfoService hostInfoService ;
25
- private readonly ILogger < SubmissionsForProcessingConsumer > logger ;
26
- private readonly IDatesService dates ;
27
-
28
- public SubmissionsForProcessingConsumer (
29
- ISubmissionsBusinessService submissionsBusiness ,
30
- IPublisherService publisher ,
31
- IHostInfoService hostInfoService ,
32
- ILogger < SubmissionsForProcessingConsumer > logger ,
33
- IDatesService dates )
34
- {
35
- this . submissionsBusiness = submissionsBusiness ;
36
- this . publisher = publisher ;
37
- this . hostInfoService = hostInfoService ;
38
- this . logger = logger ;
39
- this . dates = dates ;
40
- }
31
+ private readonly SubmissionExecutionConfig executionConfig = executionConfigAccessor . Value ;
41
32
42
33
public async Task Consume ( ConsumeContext < SubmissionForProcessingPubSubModel > context )
43
34
{
44
- var startedExecutionOn = this . dates . GetUtcNowOffset ( ) ;
45
- var workerName = this . hostInfoService . GetHostIp ( ) ;
35
+ var startedExecutionOn = dates . GetUtcNowOffset ( ) ;
36
+ var workerName = hostInfoService . GetHostIp ( ) ;
46
37
47
- this . logger . LogStartingProcessingSubmission ( context . Message . Id , workerName ) ;
38
+ logger . LogStartingProcessingSubmission ( context . Message . Id , workerName ) ;
48
39
49
40
var submissionStartedProcessingPubSubModel = new SubmissionStartedProcessingPubSubModel
50
41
{
51
42
SubmissionId = context . Message . Id ,
52
43
ProcessingStartedAt = startedExecutionOn ,
53
44
} ;
54
45
55
- await this . publisher . Publish ( submissionStartedProcessingPubSubModel ) ;
46
+ await publisher . Publish ( submissionStartedProcessingPubSubModel ) ;
56
47
57
48
var result = new ProcessedSubmissionPubSubModel ( context . Message . Id )
58
49
{
@@ -62,9 +53,9 @@ public async Task Consume(ConsumeContext<SubmissionForProcessingPubSubModel> con
62
53
try
63
54
{
64
55
var submission = context . Message . Map < SubmissionServiceModel > ( ) ;
65
- this . logger . LogExecutingSubmission ( submission . Id , submission . TrimDetails ( ) ) ;
66
- var executionResult = await this . submissionsBusiness . ExecuteSubmission ( submission ) ;
67
- this . logger . LogProducedExecutionResult ( submission . Id , executionResult ) ;
56
+ logger . LogExecutingSubmission ( submission . Id , submission . TrimDetails ( ) ) ;
57
+ var executionResult = await submissionsBusiness . ExecuteSubmission ( submission ) ;
58
+ logger . LogProducedExecutionResult ( submission . Id , executionResult ) ;
68
59
69
60
result . SetExecutionResult ( executionResult ) ;
70
61
}
@@ -75,19 +66,29 @@ public async Task Consume(ConsumeContext<SubmissionForProcessingPubSubModel> con
75
66
StrategyException => ExceptionType . Strategy ,
76
67
SolutionException => ExceptionType . Solution ,
77
68
ConfigurationException => ExceptionType . Configuration ,
78
- _ => ExceptionType . Other
69
+ _ => ExceptionType . Other ,
79
70
} ;
80
71
81
- this . logger . LogErrorProcessingSubmission ( context . Message . Id , result . WorkerName , exception ) ;
72
+ logger . LogErrorProcessingSubmission ( context . Message . Id , result . WorkerName , exception ) ;
82
73
result . SetException ( exception , true , exceptionType ) ;
83
74
}
84
-
85
75
finally
86
76
{
87
77
result . SetStartedAndCompletedExecutionOn ( startedExecutionOn . UtcDateTime , completedExecutionOn : DateTime . UtcNow ) ;
78
+
79
+ if ( context . Message . Verbosely )
80
+ {
81
+ // If the submission is marked as verbose, try to read the log file and attach it to the result
82
+ var logFilePath = FileHelpers . BuildSubmissionLogFilePath ( context . Message . Id ) ;
83
+ if ( FileHelpers . FileExists ( logFilePath ) )
84
+ {
85
+ result . VerboseLogFile = await FileHelpers . ReadFileUpToBytes ( logFilePath , this . executionConfig . SubmissionVerboseLogFileMaxBytes ) ;
86
+ FileHelpers . DeleteFile ( logFilePath ) ;
87
+ }
88
+ }
88
89
}
89
90
90
- await this . publisher . Publish ( result ) ;
91
- this . logger . LogPublishedProcessedSubmission ( context . Message . Id , result . WorkerName ) ;
91
+ await publisher . Publish ( result ) ;
92
+ logger . LogPublishedProcessedSubmission ( context . Message . Id , result . WorkerName ) ;
92
93
}
93
94
}
0 commit comments