-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathworker_scheduler.rs
78 lines (65 loc) · 2.97 KB
/
worker_scheduler.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2023 The NativeLink Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use std::sync::Arc;
use async_trait::async_trait;
use nativelink_error::Error;
use nativelink_util::action_messages::{ActionInfoHashKey, ActionStage};
use nativelink_util::metrics_utils::Registry;
use crate::platform_property_manager::PlatformPropertyManager;
use crate::worker::{Worker, WorkerId, WorkerTimestamp};
/// WorkerScheduler interface is responsible for interactions between the scheduler
/// and worker related operations.
#[async_trait]
pub trait WorkerScheduler: Sync + Send + Unpin {
/// Returns the platform property manager.
fn get_platform_property_manager(&self) -> &PlatformPropertyManager;
/// Adds a worker to the scheduler and begin using it to execute actions (when able).
async fn add_worker(&self, worker: Worker) -> Result<(), Error>;
/// Similar to `update_action()`, but called when there was an error that is not
/// related to the task, but rather the worker itself.
async fn update_action_with_internal_error(
&self,
worker_id: &WorkerId,
action_info_hash_key: &ActionInfoHashKey,
err: Error,
);
/// Updates the status of an action to the scheduler from the worker.
async fn update_action(
&self,
worker_id: &WorkerId,
action_info_hash_key: &ActionInfoHashKey,
action_stage: ActionStage,
) -> Result<(), Error>;
/// Event for when the keep alive message was received from the worker.
async fn worker_keep_alive_received(
&self,
worker_id: &WorkerId,
timestamp: WorkerTimestamp,
) -> Result<(), Error>;
/// Send a request to kill a running action
async fn kill_running_action_on_worker(
&self,
worker_id: &WorkerId,
unique_qualifier: &ActionInfoHashKey,
) -> Result<(), Error>;
/// Removes worker from pool and reschedule any tasks that might be running on it.
async fn remove_worker(&self, worker_id: WorkerId);
/// Removes timed out workers from the pool. This is called periodically by an
/// external source.
async fn remove_timedout_workers(&self, now_timestamp: WorkerTimestamp) -> Result<(), Error>;
/// Sets if the worker is draining or not.
async fn set_drain_worker(&self, worker_id: WorkerId, is_draining: bool) -> Result<(), Error>;
/// Register the metrics for the worker scheduler.
fn register_metrics(self: Arc<Self>, _registry: &mut Registry) {}
}