lazhen
2025-01-07 b3987122cbbc46c5c59d3173f37fca3170b6dc5a
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
Quintiq file version 2.0
#parent: #root
Method CheckOptimizerRunController () as stream[JSON]
{
  Description:
  [*
    Check with the `LibOpt_OptimizerRunController` whether this `LibOpt_Run` can start.
    Then start the run once the `LibOpt_OptimizerRunController` gives its approval.
  *]
  TextBody:
  [*
    // evr3 Apr-26-2022 (created)
    
    snapshotruncontroller := LibOpt_SnapshotOptimizerRunController::Create( this, this.RequestedOn() );
    // Create the controller run.
    // Note: We don't pass objects from the optimizer components library to the dataset controller.
    // This is to ensure that the transaction doesn't put a lock on the dataset of the LibOpt_Run.  
    // Note2: The run controller will throw an error if it is impossible to start a run. 
    controllerrun := LibOpt_OptimizerRunController::GetRunControllerDataset()
                     ->LibOpt_ControllerRun::Create( this.Optimizer().Optimization().DatasetName(),
                                                     this.MDSID(),
                                                     this.OptimizerName(),
                                                     this.Key(),
                                                     this.RunNr(), 
                                                     this.RequestedOn(), 
                                                     this.RequestedThreadsRunController() );
    // Check with the run controller if the run satisfies all conditions
    canstart := controllerrun->CanStart(); 
    // Otherwise, keep polling the run controller until the run satisfies the conditions. 
    canstart := controllerrun->PollOptimizerRunController( canstart );
    result := this->StartAfterPreprocessing( canstart, snapshotruncontroller );
    
    // Tell the run controller that the run has ended and that any reservations for this LibOpt_Run can be released. 
    result->|controllerrun->End()
    // Handle the error that is thrown when it is impossible to start a run.
             ->Exception()
             ->LibOpt_OptimizerRunController::HandleExceptionRunController( this, snapshotruncontroller );
    
    return result;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}