@@ -238,8 +238,9 @@ func (t *Task) GetControlMode() controlmode.ControlMode {
238238 // If it's a BASIC task but its parent role uses it as a HOOK,
239239 // we modify the actual control mode of the task.
240240 // The class itself can never be HOOK, only BASIC
241- if class .Control .Mode == controlmode .BASIC && t .GetParent () != nil {
242- traits := t .GetParent ().GetTaskTraits ()
241+ parent := t .GetParent ()
242+ if class .Control .Mode == controlmode .BASIC && parent != nil {
243+ traits := parent .GetTaskTraits ()
243244 if len (traits .Trigger ) > 0 {
244245 return controlmode .HOOK
245246 }
@@ -409,7 +410,7 @@ func (t *Task) BuildTaskCommand(role parentRole) (err error) {
409410 // If it's a HOOK, we must pass the Timeout to the TCI for
410411 // executor-side timeout enforcement
411412 if cmd .ControlMode == controlmode .HOOK || cmd .ControlMode == controlmode .BASIC {
412- traits := t . GetParent () .GetTaskTraits ()
413+ traits := role .GetTaskTraits ()
413414 cmd .Timeout , err = time .ParseDuration (traits .Timeout )
414415 }
415416
@@ -579,7 +580,8 @@ func (t *Task) BuildPropertyMap(bindMap channel.BindMap) (propMap controlcommand
579580 propMap = make (controlcommands.PropertyMap )
580581 if class := t .GetTaskClass (); class != nil {
581582 if class .Control .Mode != controlmode .BASIC { // if it's NOT a basic task or hook, we template the props
582- if t .GetParent () == nil {
583+ parent := t .GetParent ()
584+ if parent == nil {
583585 err = fmt .Errorf ("cannot build property map for parentless task %s (id %s)" , t .name , t .taskId )
584586 return
585587 }
@@ -590,7 +592,7 @@ func (t *Task) BuildPropertyMap(bindMap channel.BindMap) (propMap controlcommand
590592 // First we get the full varStack from the parent role, and
591593 // consolidate it.
592594 var varStack map [string ]string
593- varStack , err = t . GetParent () .ConsolidatedVarStack ()
595+ varStack , err = parent .ConsolidatedVarStack ()
594596 if err != nil {
595597 err = fmt .Errorf ("cannot fetch variables stack for property map: %w" , err )
596598 return
@@ -616,7 +618,7 @@ func (t *Task) BuildPropertyMap(bindMap channel.BindMap) (propMap controlcommand
616618
617619 // Finally we build the task-specific special values, and write them
618620 // into the varStack (overwriting anything).
619- specialVarStack := t .buildSpecialVarStack (t . GetParent () )
621+ specialVarStack := t .buildSpecialVarStack (parent )
620622 for k , v := range specialVarStack {
621623 varStack [k ] = v
622624 }
@@ -634,7 +636,7 @@ func (t *Task) BuildPropertyMap(bindMap channel.BindMap) (propMap controlcommand
634636 // For FAIRMQ tasks, we append FairMQ channel configuration
635637 if class .Control .Mode == controlmode .FAIRMQ ||
636638 class .Control .Mode == controlmode .DIRECT {
637- for _ , inbCh := range channel .MergeInbound (t . GetParent () .CollectInboundChannels (), class .Bind ) {
639+ for _ , inbCh := range channel .MergeInbound (parent .CollectInboundChannels (), class .Bind ) {
638640 // We get the FairMQ-formatted propertyMap from the inbound channel spec
639641 var chanProps controlcommands.PropertyMap
640642 chanProps , err = inbCh .ToFMQMap (t .localBindMap )
@@ -647,7 +649,7 @@ func (t *Task) BuildPropertyMap(bindMap channel.BindMap) (propMap controlcommand
647649 propMap [k ] = v
648650 }
649651 }
650- for _ , outboundCh := range channel .MergeOutbound (t . GetParent () .CollectOutboundChannels (), class .Connect ) {
652+ for _ , outboundCh := range channel .MergeOutbound (parent .CollectOutboundChannels (), class .Connect ) {
651653 // We get the FairMQ-formatted propertyMap from the outbound channel spec
652654 var chanProps controlcommands.PropertyMap
653655 chanProps , err = outboundCh .ToFMQMap (bindMap )
@@ -672,7 +674,7 @@ func (t *Task) BuildPropertyMap(bindMap channel.BindMap) (propMap controlcommand
672674 err = fields .Execute (the .ConfSvc (), t .name , varStack , objStack , nil , make (map [string ]texttemplate.Template ), nil )
673675 if err != nil {
674676 log .WithError (err ).
675- WithField ("partition" , t . GetParent () .GetEnvironmentId ().String ()).
677+ WithField ("partition" , parent .GetEnvironmentId ().String ()).
676678 WithField ("detector" , detector ).
677679 Error ("cannot resolve templates for property map" )
678680 return
@@ -718,13 +720,14 @@ func (t *Task) GetMesosCommandTarget() controlcommands.MesosCommandTarget {
718720}
719721
720722func (t * Task ) GetProperties () map [string ]string {
721- t .mu .RLock ()
722- defer t .mu .RUnlock ()
723-
724723 if t == nil {
725724 log .Warn ("attempted to get properties of nil task" )
726725 return make (map [string ]string )
727726 }
727+
728+ t .mu .RLock ()
729+ defer t .mu .RUnlock ()
730+
728731 propertiesMap , err := t .properties .Flattened ()
729732 if err != nil {
730733 return make (map [string ]string )
@@ -733,22 +736,24 @@ func (t *Task) GetProperties() map[string]string {
733736}
734737
735738func (t * Task ) setTaskPID (pid int ) {
736- t .mu .Lock ()
737- defer t .mu .Unlock ()
738-
739739 if t == nil {
740740 return
741741 }
742+
743+ t .mu .Lock ()
744+ defer t .mu .Unlock ()
745+
742746 t .pid = strconv .Itoa (pid )
743747}
744748
745749func (t * Task ) GetTaskPID () string {
746- t .mu .RLock ()
747- defer t .mu .RUnlock ()
748-
749750 if t == nil {
750751 return ""
751752 }
753+
754+ t .mu .RLock ()
755+ defer t .mu .RUnlock ()
756+
752757 return t .pid
753758}
754759
@@ -767,11 +772,5 @@ func (t *Task) SetParent(parent parentRole) {
767772}
768773
769774func (t * Task ) GetTask () * Task {
770- if t == nil {
771- return nil
772- }
773- t .mu .RLock ()
774- defer t .mu .RUnlock ()
775-
776775 return t
777776}
0 commit comments