Skip to content

Commit

Permalink
feat: display running job id in workers page
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Apr 5, 2024
1 parent 80ac4bc commit 6028130
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions frontend/src/pages/workers/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
</v-chip>
<br/>
Last seen {{ new TimeAgo('en-US').format(new Date((item as Worker).last_heartbeat_time)) }}
<div v-if="(item as Worker).running_job_id !== null && (item as Worker).running_job_id !== undefined">
<br/>
Running job
<router-link :to="{ path: `/jobs/${(item as Worker).running_job_id}` }">
# {{ (item as Worker).running_job_id }}
</router-link>
</div>
</template>
</v-data-table-server>
</v-col>
Expand Down Expand Up @@ -71,6 +78,7 @@
logical_cores: number;
memory_bytes: number;
disk_free_space_bytes: number;
running_job_id: number;
}
export default {
Expand Down
21 changes: 17 additions & 4 deletions server/src/routes/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use common::{
WorkerPollResponse,
};

use diesel::BoolExpressionMethods;
use diesel::{BoolExpressionMethods, JoinOnDsl, NullableExpressionMethods};
use diesel::{Connection, ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl};
use octocrab::models::CheckRunId;
use octocrab::params::checks::CheckRunConclusion;
Expand Down Expand Up @@ -46,6 +46,8 @@ pub struct WorkerListResponseItem {
disk_free_space_bytes: i64,
is_live: bool,
last_heartbeat_time: DateTime<Utc>,
// status
running_job_id: Option<i32>,
}

#[derive(Serialize)]
Expand All @@ -71,18 +73,28 @@ pub async fn worker_list(
let workers = if query.items_per_page == -1 {
crate::schema::workers::dsl::workers
.order_by(crate::schema::workers::dsl::arch)
.load::<Worker>(conn)?
.left_join(
crate::schema::jobs::dsl::jobs
.on(crate::schema::jobs::dsl::assigned_worker_id
.eq(crate::schema::workers::dsl::id.nullable())),
)
.load::<(Worker, Option<Job>)>(conn)?
} else {
crate::schema::workers::dsl::workers
.order_by(crate::schema::workers::dsl::arch)
.offset((query.page - 1) * query.items_per_page)
.limit(query.items_per_page)
.load::<Worker>(conn)?
.left_join(
crate::schema::jobs::dsl::jobs
.on(crate::schema::jobs::dsl::assigned_worker_id
.eq(crate::schema::workers::dsl::id.nullable())),
)
.load::<(Worker, Option<Job>)>(conn)?
};

let mut items = vec![];
let deadline = Utc::now() - chrono::Duration::try_seconds(300).unwrap();
for worker in workers {
for (worker, job) in workers {
items.push(WorkerListResponseItem {
id: worker.id,
hostname: worker.hostname,
Expand All @@ -92,6 +104,7 @@ pub async fn worker_list(
disk_free_space_bytes: worker.disk_free_space_bytes,
is_live: worker.last_heartbeat_time > deadline,
last_heartbeat_time: worker.last_heartbeat_time,
running_job_id: job.map(|job| job.id),
});
}

Expand Down

0 comments on commit 6028130

Please sign in to comment.