/build/source/nativelink-scheduler/src/worker_scheduler.rs
Line | Count | Source |
1 | | // Copyright 2024 The NativeLink Authors. All rights reserved. |
2 | | // |
3 | | // Licensed under the Functional Source License, Version 1.1, Apache 2.0 Future License (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 | | // See LICENSE file for details |
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 | | use async_trait::async_trait; |
16 | | use nativelink_error::Error; |
17 | | use nativelink_metric::RootMetricsComponent; |
18 | | use nativelink_proto::com::github::trace_machina::nativelink::remote_execution::ActionResourceUsage; |
19 | | use nativelink_util::action_messages::{OperationId, WorkerId}; |
20 | | use nativelink_util::operation_state_manager::UpdateOperationType; |
21 | | use nativelink_util::shutdown_guard::ShutdownGuard; |
22 | | |
23 | | use crate::platform_property_manager::PlatformPropertyManager; |
24 | | use crate::worker::{Worker, WorkerTimestamp}; |
25 | | |
26 | | /// `WorkerScheduler` interface is responsible for interactions between the scheduler |
27 | | /// and worker related operations. |
28 | | #[async_trait] |
29 | | pub trait WorkerScheduler: Sync + Send + Unpin + RootMetricsComponent + 'static { |
30 | | /// Returns the platform property manager. |
31 | | fn get_platform_property_manager(&self) -> &PlatformPropertyManager; |
32 | | |
33 | | /// Adds a worker to the scheduler and begin using it to execute actions (when able). |
34 | | async fn add_worker(&self, worker: Worker) -> Result<(), Error>; |
35 | | |
36 | | /// Updates the status of an action to the scheduler from the worker. |
37 | | async fn update_action( |
38 | | &self, |
39 | | worker_id: &WorkerId, |
40 | | operation_id: &OperationId, |
41 | | update: UpdateOperationType, |
42 | | ) -> Result<(), Error>; |
43 | | |
44 | | /// Records worker-observed resource usage for a running action. |
45 | | async fn record_action_resource_usage( |
46 | | &self, |
47 | | _worker_id: &WorkerId, |
48 | | _operation_id: &OperationId, |
49 | | _resource_usage: ActionResourceUsage, |
50 | 0 | ) -> Result<(), Error> { |
51 | | Ok(()) |
52 | 0 | } |
53 | | |
54 | | /// Event for when the keep alive message was received from the worker. |
55 | | async fn worker_keep_alive_received( |
56 | | &self, |
57 | | worker_id: &WorkerId, |
58 | | timestamp: WorkerTimestamp, |
59 | | ) -> Result<(), Error>; |
60 | | |
61 | | /// Removes worker from pool and reschedule any tasks that might be running on it. |
62 | | async fn remove_worker(&self, worker_id: &WorkerId) -> Result<(), Error>; |
63 | | |
64 | | /// Evict all workers from the scheduler, setting their actions back to queued. |
65 | | async fn shutdown(&self, shutdown_guard: ShutdownGuard); |
66 | | |
67 | | /// Removes timed out workers from the pool. This is called periodically by an |
68 | | /// external source. |
69 | | async fn remove_timedout_workers(&self, now_timestamp: WorkerTimestamp) -> Result<(), Error>; |
70 | | |
71 | | /// Sets if the worker is draining or not. |
72 | | async fn set_drain_worker(&self, worker_id: &WorkerId, is_draining: bool) -> Result<(), Error>; |
73 | | } |