haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
Quintiq file version 2.0
#parent: #root
MethodOverride HandleRollback (
  LibOpt_Task task
)
{
  TextBody:
  [*
    task.RecoverFromRollback();
    
    // recover scaling factor sugesstions, in case those were computed
    
    Transaction::Transaction().Propagate( relation( SnapshotMacroPlannerOptimizer, LibOpt_Run ) ); // need to have correct last snapshot ( declarative relation, used next line)
    Transaction::Transaction().Propagate( relation( SnapshotMacroPlannerOptimizer, PreviousSnapshotMacroPlannerOptimizer ) ); // need the sorting
    Transaction::Transaction().Propagate( attribute( SnapshotMacroPlannerOptimizer, Type ) ); // need to have type below for assert check
    
    snapshot := task.Run().LastSnapshotMacroPlannerOptimizer().PreviousSnapshotMacroPlannerOptimizer(); // last created is post handle result snapshot 
    assert(  snapshot.Type() ~ Translations::LibOpt_SnapshotKPI_CommentPreHandleResult(),  
             'Snapshot type = '+ snapshot.Type() 
              + ' Snapshot used to recover scale factor suggestions is expected to be pre handle result snapshot. Snapshot.seqnr[key]=' 
              + [String] snapshot.SequenceNr() + [String]snapshot.Key() 
              + 'run last snapshot = ' + guard([String]task.Run().LastSnapshotMacroPlannerOptimizer().Key(), 'null' ) ); 
    
    if ( snapshot.ScaleFactorSuggestedForLevel().Size()  > 0 and this.IsAutoScalingEnabled() ) 
    {
      debuginfo( 'Restoring suggested scale factors using snapshot (seqnr, key) = ', snapshot.SequenceNr(), snapshot.Key() ); 
      ScaleFactorsSuggestedForLevel::Construct( snapshot.ScaleFactorSuggestedForLevel(), task.Run().Optimization().astype( Optimization ).AlgorithmScaling() ); // recover suggested scale factors
    }
    
    // Log the rollback
    kpi := this.LogKPI( task, Translations::LibOpt_Rollback() );
    kpi.astype( SnapshotMacroPlannerOptimizer ).IsAccepted( true );
    kpi.astype( SnapshotMacroPlannerOptimizer ).Parent( relset, guard( kpi.astype( SnapshotMacroPlannerOptimizer ).PreviousOnRun().Parent(), null( LibOpt_Snapshot ) ) ); // need to set parent to get in included in the hierarchy
  *]
}