github.com/matrixorigin/matrixone@v0.7.0/pkg/pb/task/task.go (about)

     1  // Copyright 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package task
    16  
    17  import (
    18  	"fmt"
    19  	"time"
    20  )
    21  
    22  // IsDelayTask returns true if the task is a delay task
    23  func (m Task) IsDelayTask() bool {
    24  	return m.Metadata.Options.DelayDuration > 0
    25  }
    26  
    27  // IsInitTask returns true if the task is an init task
    28  func (m Task) IsInitTask() bool {
    29  	return m.Metadata.Executor == TaskCode_SystemInit
    30  }
    31  
    32  // GetDelayDuration returns delay duration
    33  func (m Task) GetDelayDuration() time.Duration {
    34  	return time.Duration(m.Metadata.Options.DelayDuration)
    35  }
    36  
    37  // DebugString returns the debug string
    38  func (m Task) DebugString() string {
    39  	return fmt.Sprintf("%s/%d", m.Metadata.ID, m.Metadata.Executor)
    40  }
    41  
    42  // DebugString returns the debug string
    43  func (m CronTask) DebugString() string {
    44  	return fmt.Sprintf("%s/%d/%s",
    45  		m.Metadata.ID,
    46  		m.TriggerTimes,
    47  		m.CronExpr)
    48  }