-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtask.rs
60 lines (53 loc) · 1.7 KB
/
task.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
use crate::{
package::simulation::init::js_py::{TsInitTask, JsInitTask, PyInitTask},
task::{
StoreAccessValidator, TargetedTaskMessage, Task, TaskDistributionConfig, TaskSharedStore,
},
worker::WorkerHandler,
worker_pool::WorkerPoolHandler,
Error, Result,
};
/// All init package tasks are registered in this enum
#[derive(Clone, Debug)]
pub enum InitTask {
JsInitTask(JsInitTask),
TsInitTask(TsInitTask),
PyInitTask(PyInitTask),
}
impl Task for InitTask {
fn name(&self) -> &'static str {
match self {
Self::JsInitTask(task) => task.name(),
Self::TsInitTask(task) => task.name(),
Self::PyInitTask(task) => task.name(),
}
}
fn distribution(&self) -> TaskDistributionConfig {
match self {
Self::JsInitTask(task) => task.distribution(),
Self::TsInitTask(task) => task.distribution(),
Self::PyInitTask(task) => task.distribution(),
}
}
}
impl StoreAccessValidator for InitTask {
fn verify_store_access(&self, access: &TaskSharedStore) -> Result<()> {
let state = &access.state;
let context = access.context();
if state.is_disabled() && context.is_disabled() {
Ok(())
} else {
Err(Error::access_not_allowed(state, context, "Init".into()))
}
}
}
impl WorkerHandler for InitTask {
fn start_message(&self) -> Result<TargetedTaskMessage> {
match self {
Self::JsInitTask(inner) => inner.start_message(),
Self::TsInitTask(inner) => inner.start_message(),
Self::PyInitTask(inner) => inner.start_message(),
}
}
}
impl WorkerPoolHandler for InitTask {}