github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/pkg/orm/model/jobop.go (about)

     1  // Copyright 2022 PingCAP, Inc.
     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  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package model
    15  
    16  // JobOpStatus represents the expected status of a job, note this status diffs
    17  // from the worker status defined in framework model, the relationship of these
    18  // two status system is as follows.
    19  // - JobOpStatusCanceling, no mapping
    20  // - JobOpStatusCanceled maps to WorkerStatusStopped
    21  type JobOpStatus int8
    22  
    23  // Defines all JobOpStatus
    24  const (
    25  	// noop is reserved for some unexpected scenario, such as job operation of
    26  	// a nonexistent job
    27  	JobOpStatusNoop      = JobOpStatus(1)
    28  	JobOpStatusCanceling = JobOpStatus(2)
    29  	JobOpStatusCanceled  = JobOpStatus(3)
    30  )
    31  
    32  // JobOpUpdateColumns is used in gorm update.
    33  // TODO: using reflect to generate it more generally
    34  // related to some implement of gorm
    35  var JobOpUpdateColumns = []string{
    36  	"updated_at",
    37  	"op",
    38  	"job_id",
    39  }
    40  
    41  // JobOp stores job operation recoreds
    42  type JobOp struct {
    43  	Model
    44  	Op    JobOpStatus `gorm:"type:tinyint not null;index:idx_job_op,priority:2;comment:Canceling(1),Canceled(2)"`
    45  	JobID string      `gorm:"type:varchar(128) not null;uniqueIndex:uk_job_id"`
    46  }
    47  
    48  // Map is used for update in orm model
    49  func (op *JobOp) Map() map[string]interface{} {
    50  	return map[string]interface{}{
    51  		"op": op.Op,
    52  	}
    53  }