github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/model/job.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 type ( 17 // JobID is the unique identifier of a job 18 JobID = string 19 // JobType is the type of a type, like `CVSDEMO`, `DM`, `CDC`. 20 JobType int32 21 ) 22 23 // Define job type 24 const ( 25 JobTypeInvalid = JobType(iota) 26 // job type for job manager, only for inner use 27 JobTypeJobManager 28 JobTypeCVSDemo 29 JobTypeDM 30 JobTypeCDC 31 JobTypeFakeJob 32 ) 33 34 // Define job type name 35 const ( 36 JobTypeNameInvalid = "Invalid" 37 JobTypeNameJobManager = "JobManager" 38 JobTypeNameCVSDemo = "CVSDemo" 39 JobTypeNameDM = "DM" 40 JobTypeNameCDC = "CDC" 41 JobTypeNameFakeJob = "FakeJob" 42 ) 43 44 // jobTypeNameToType maintains the valid job name and job type 45 var jobTypeNameToType = map[string]JobType{ 46 JobTypeNameCVSDemo: JobTypeCVSDemo, 47 JobTypeNameDM: JobTypeDM, 48 JobTypeNameCDC: JobTypeCDC, 49 JobTypeNameFakeJob: JobTypeFakeJob, 50 } 51 52 // GetJobTypeByName get JobType by readable job name 53 func GetJobTypeByName(name string) (JobType, bool) { 54 tp, exists := jobTypeNameToType[name] 55 if !exists { 56 return JobTypeInvalid, false 57 } 58 59 return tp, true 60 } 61 62 func (j JobType) String() string { 63 switch j { 64 case JobTypeCVSDemo: 65 return JobTypeNameCVSDemo 66 case JobTypeDM: 67 return JobTypeNameDM 68 case JobTypeCDC: 69 return JobTypeNameCDC 70 case JobTypeFakeJob: 71 return JobTypeNameFakeJob 72 case JobTypeJobManager: 73 return JobTypeNameJobManager 74 } 75 76 return JobTypeNameInvalid 77 }