Skip to content

Commit 013bbb6

Browse files
committed
Put all relevant structs in TaskInfo for future extensibility
1 parent bec2630 commit 013bbb6

1 file changed

Lines changed: 32 additions & 11 deletions

File tree

cli/src/client.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55
fs,
66
io::{Cursor, ErrorKind},
77
iter::{self, Empty},
8-
path::{Path, PathBuf},
8+
path::Path,
99
process::{Output, Stdio},
1010
sync::Arc,
1111
time::Duration,
@@ -36,8 +36,9 @@ struct ClusterizerClient {
3636

3737
struct TaskInfo {
3838
task: Task,
39+
project: Project,
40+
project_version: ProjectVersion,
3941
file: File,
40-
program_dir: PathBuf,
4142
}
4243

4344
enum Return {
@@ -139,11 +140,16 @@ impl ClusterizerClient {
139140
.await?
140141
.into_iter()
141142
.filter_map(|task| {
142-
let file_path = self.args.cache_dir.join("bin");
143+
let project = projects.get(&task.project_id)?;
144+
let file = files.get(&task.project_id)?;
145+
let project_version = project_versions
146+
.iter()
147+
.find(|(_, project_version)| project_version.file_id == file.id)?;
143148
let info = files.get(&task.project_id).map(|file| TaskInfo {
144149
task,
145150
file: file.clone(),
146-
program_dir: file_path.clone().join(format!("{:x}", file)),
151+
project: project.clone(),
152+
project_version: project_version.1.clone(),
147153
});
148154

149155
if info.is_none() {
@@ -162,11 +168,17 @@ impl ClusterizerClient {
162168
time::sleep(Duration::from_millis(15000)).await;
163169
};
164170

165-
for TaskInfo {
166-
program_dir, file, ..
167-
} in &tasks
168-
{
169-
download_archive(&file.url, program_dir, &self.args.cache_dir).await?;
171+
for TaskInfo { file, .. } in &tasks {
172+
download_archive(
173+
&file.url,
174+
self.args
175+
.cache_dir
176+
.join("bin")
177+
.join(format!("{:x}", file))
178+
.as_path(),
179+
&self.args.cache_dir,
180+
)
181+
.await?;
170182
}
171183

172184
Ok(Return::FetchTasks(tasks))
@@ -175,15 +187,24 @@ impl ClusterizerClient {
175187
async fn execute_task(
176188
self: Arc<Self>,
177189
TaskInfo {
178-
task, program_dir, ..
190+
task,
191+
project_version,
192+
project,
193+
file,
179194
}: TaskInfo,
180195
) -> ClientResult<Return> {
181196
let slot_dir = tempfile::tempdir()?;
182197

183198
info!("Task id: {}, stdin: {}", task.id, task.stdin);
184-
info!("Project id: {}", task.project_id);
199+
info!(
200+
"Project id: {}, Project name: {}",
201+
task.project_id, project.name
202+
);
203+
debug!("Platform id: {}", project_version.platform_id);
185204
debug!("Slot dir: {}", slot_dir.path().display());
186205

206+
let program_dir = self.args.cache_dir.join("bin").join(format!("{:x}", file));
207+
187208
let program = program_dir
188209
.join(format!("main{}", env::consts::EXE_SUFFIX))
189210
.canonicalize()?;

0 commit comments

Comments
 (0)