Skip to content

Commit 4be8cbc

Browse files
Schedule preemptible batch jobs properly. (#4433)
1 parent f7a2037 commit 4be8cbc

File tree

1 file changed

+11
-0
lines changed
  • src/clusterfuzz/_internal/google_cloud_utils

1 file changed

+11
-0
lines changed

src/clusterfuzz/_internal/google_cloud_utils/batch.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ def _get_task_spec(batch_workload_spec):
144144
return task_spec
145145

146146

147+
def _set_preemptible(instance_policy,
148+
batch_workload_spec: BatchWorkloadSpec) -> None:
149+
if batch_workload_spec.preemptible:
150+
instance_policy.provisioning_model = (
151+
batch.AllocationPolicy.ProvisioningModel.PREEMPTIBLE)
152+
else:
153+
instance_policy.provisioning_model = (
154+
batch.AllocationPolicy.ProvisioningModel.STANDARD)
155+
156+
147157
def _get_allocation_policy(spec):
148158
"""Returns the allocation policy for a BatchWorkloadSpec."""
149159
disk = batch.AllocationPolicy.Disk()
@@ -153,6 +163,7 @@ def _get_allocation_policy(spec):
153163
instance_policy = batch.AllocationPolicy.InstancePolicy()
154164
instance_policy.boot_disk = disk
155165
instance_policy.machine_type = spec.machine_type
166+
_set_preemptible(instance_policy, spec)
156167
instances = batch.AllocationPolicy.InstancePolicyOrTemplate()
157168
instances.policy = instance_policy
158169

0 commit comments

Comments
 (0)