go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/led/job/jobcreate/raw.go (about)

     1  // Copyright 2020 The LUCI Authors.
     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 jobcreate
    16  
    17  import (
    18  	"go.chromium.org/luci/led/job"
    19  	swarmingpb "go.chromium.org/luci/swarming/proto/api_v2"
    20  )
    21  
    22  func jobDefinitionFromSwarming(sw *job.Swarming, r *swarmingpb.NewTaskRequest) {
    23  	// we ignore r.Properties; TaskSlices are the only thing generated from modern
    24  	// swarming tasks.
    25  	// TODO(b/296244642): Remove redundant job.Swarming.Task <-> swarming.NewTaskRequest conversion
    26  	sw.Task = &swarmingpb.NewTaskRequest{}
    27  	t := sw.Task
    28  
    29  	t.TaskSlices = make([]*swarmingpb.TaskSlice, len(r.TaskSlices))
    30  	for i, inslice := range r.TaskSlices {
    31  		outslice := &swarmingpb.TaskSlice{
    32  			ExpirationSecs:  inslice.ExpirationSecs,
    33  			Properties:      inslice.Properties,
    34  			WaitForCapacity: inslice.WaitForCapacity,
    35  		}
    36  		t.TaskSlices[i] = outslice
    37  	}
    38  
    39  	t.Priority = int32(r.Priority) + 10
    40  	t.ServiceAccount = r.ServiceAccount
    41  	t.Realm = r.Realm
    42  	// CreateTime is unused for new task requests
    43  	// Name is overwritten
    44  	// Tags should not be explicitly provided by the user for the new task
    45  	t.User = r.User
    46  	// TaskId is unpopulated for new task requests
    47  	// ParentTaskId is unpopulated for new task requests
    48  	// ParentRunId is unpopulated for new task requests
    49  	// PubsubNotification is intentionally not propagated.
    50  	t.BotPingToleranceSecs = r.BotPingToleranceSecs
    51  }