@@ -73,27 +73,45 @@ public async Task<Unit> Handle(RunScheduleJobSessionCommand cmd, CancellationTok
73
73
ScheduleJobSessionResp ? resp = await _scheduleJobSessionRepository . GetAsync ( cmd . JobSessionId , ct ) ;
74
74
if ( resp == null )
75
75
{
76
- throw new ApiException ( HttpStatusCode . BadRequest , "The schedule job session does not exist." ) ;
76
+ string err = "The schedule job session does not exist." ;
77
+ _logger . LogError ( err ) ;
78
+ throw new ApiException ( HttpStatusCode . BadRequest , err ) ;
77
79
}
78
80
79
- Stopwatch stopwatch = Stopwatch . StartNew ( ) ;
80
- using var cts = new CancellationTokenSource ( ) ; // no timeout, this is the resolve for mysteriously cancelled requests
81
- //request will from bcgov_schedulejob
82
- //filterStr should be like "statecode eq 0 and spd_eligibleforcreditpayment eq 100000001"
83
- RunJobRequest request = new RunJobRequest
81
+ try
84
82
{
85
- PrimaryTypeName = resp . PrimaryEntity ,
86
- PrimaryEntityActionStr = resp . EndPoint ,
87
- PrimaryEntityName = resp . PrimaryEntity + "s" ,
88
- PrimaryEntityFilterStr = resp . FilterStr . Trim ( ) ,
89
- PrimaryEntityIdName = resp . PrimaryEntity + "id" ,
90
- } ;
91
- var result = await _generalizeScheduleJobRepository . RunJobsAsync ( request , cmd . ConcurrentRequests , cts . Token ) ;
92
- stopwatch . Stop ( ) ;
83
+ Stopwatch stopwatch = Stopwatch . StartNew ( ) ;
84
+ using var cts = new CancellationTokenSource ( ) ; // no timeout, this is the resolve for mysteriously cancelled requests
85
+ //request will from bcgov_schedulejob
86
+ //filterStr should be like "statecode eq 0 and spd_eligibleforcreditpayment eq 100000001"
87
+ RunJobRequest request = new RunJobRequest
88
+ {
89
+ PrimaryTypeName = resp . PrimaryEntity ,
90
+ PrimaryEntityActionStr = resp . EndPoint ,
91
+ PrimaryEntityName = resp . PrimaryEntity + "s" ,
92
+ PrimaryEntityFilterStr = resp . FilterStr . Trim ( ) ,
93
+ PrimaryEntityIdName = resp . PrimaryEntity + "id" ,
94
+ } ;
95
+ var result = await _generalizeScheduleJobRepository . RunJobsAsync ( request , cmd . ConcurrentRequests , cts . Token ) ;
96
+ stopwatch . Stop ( ) ;
93
97
94
- //update result in JobSession
95
- UpdateScheduleJobSessionCmd updateResultCmd = CreateUpdateScheduleJobSessionCmd ( cmd . JobSessionId , result , Decimal . Round ( ( decimal ) ( stopwatch . ElapsedMilliseconds / 1000 ) , 2 ) ) ;
96
- await _scheduleJobSessionRepository . ManageAsync ( updateResultCmd , cts . Token ) ;
98
+ //update result in JobSession
99
+ UpdateScheduleJobSessionCmd updateResultCmd = CreateUpdateScheduleJobSessionCmd ( cmd . JobSessionId , result , Decimal . Round ( ( decimal ) ( stopwatch . ElapsedMilliseconds / 1000 ) , 2 ) ) ;
100
+ await _scheduleJobSessionRepository . ManageAsync ( updateResultCmd , cts . Token ) ;
101
+ }
102
+ catch ( Exception ex )
103
+ {
104
+ string err = ex . Message ;
105
+ if ( ex . InnerException != null )
106
+ err += ex . InnerException . Message ;
107
+ _logger . LogError ( err ) ;
108
+ UpdateScheduleJobSessionCmd updateCmd = new UpdateScheduleJobSessionCmd ( ) ;
109
+ updateCmd . ScheduleJobSessionId = cmd . JobSessionId ;
110
+ updateCmd . JobSessionStatusCode = JobSessionStatusCode . Failed ;
111
+ updateCmd . ErrorMsg = err ;
112
+ //update result in JobSession
113
+ await _scheduleJobSessionRepository . ManageAsync ( updateCmd , ct ) ;
114
+ }
97
115
98
116
return default ;
99
117
}
0 commit comments