Skip to content

Commit

Permalink
Schedule preemptible batch jobs properly. (#4433)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanmetzman authored Nov 25, 2024
1 parent f7a2037 commit 4be8cbc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/clusterfuzz/_internal/google_cloud_utils/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ def _get_task_spec(batch_workload_spec):
return task_spec


def _set_preemptible(instance_policy,
batch_workload_spec: BatchWorkloadSpec) -> None:
if batch_workload_spec.preemptible:
instance_policy.provisioning_model = (
batch.AllocationPolicy.ProvisioningModel.PREEMPTIBLE)
else:
instance_policy.provisioning_model = (
batch.AllocationPolicy.ProvisioningModel.STANDARD)


def _get_allocation_policy(spec):
"""Returns the allocation policy for a BatchWorkloadSpec."""
disk = batch.AllocationPolicy.Disk()
Expand All @@ -153,6 +163,7 @@ def _get_allocation_policy(spec):
instance_policy = batch.AllocationPolicy.InstancePolicy()
instance_policy.boot_disk = disk
instance_policy.machine_type = spec.machine_type
_set_preemptible(instance_policy, spec)
instances = batch.AllocationPolicy.InstancePolicyOrTemplate()
instances.policy = instance_policy

Expand Down

0 comments on commit 4be8cbc

Please sign in to comment.