-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathjob.rs
More file actions
44 lines (36 loc) · 1.09 KB
/
job.rs
File metadata and controls
44 lines (36 loc) · 1.09 KB
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
use std::ops::{Deref, DerefMut};
use anyhow::{Context, Result};
use sift_rs::{
SiftChannel,
jobs::v1::{Job, ListJobsRequest, job_service_client::JobServiceClient},
};
pub struct JobServiceWrapper(JobServiceClient<SiftChannel>);
impl Deref for JobServiceWrapper {
type Target = JobServiceClient<SiftChannel>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for JobServiceWrapper {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl JobServiceWrapper {
pub fn new(grpc_channel: SiftChannel) -> Self {
let job_service = JobServiceClient::new(grpc_channel);
JobServiceWrapper(job_service)
}
pub async fn get_job(&mut self, job_id: &str) -> Result<Option<Job>> {
let res = self
.list_jobs(ListJobsRequest {
page_size: 1,
filter: format!("job_id == '{job_id}'"),
..Default::default()
})
.await
.context("failed to retrieve job by ID")?
.into_inner();
Ok(res.jobs.first().cloned())
}
}