Skip to content

Commit

Permalink
feat: add job restart to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Mar 14, 2024
1 parent d0a930e commit 18098bb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
34 changes: 31 additions & 3 deletions frontend/src/pages/jobs/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<v-row>
<v-col>
<v-data-table-server
:page="page"
:items-per-page="itemsPerPage"
:headers="headers"
:items="serverItems"
Expand Down Expand Up @@ -132,16 +133,32 @@
rounded
size="x-small"
v-if="(item as Job).log_url !== null && (item as Job).log_url !== undefined"
:to="{ path: (item as Job).log_url.replace('https://buildit.aosc.io/logs/', '/web-logs/') }">
:to="{ path: (item as Job).log_url.replace('https://buildit.aosc.io/logs/', '/web-logs/') }"
style="margin-right: 5px;margin-bottom: 5px;">
<v-icon>mdi:mdi-history</v-icon>
<v-tooltip activator="parent" location="bottom">
View Log
</v-tooltip>
</v-btn>
<v-btn
icon="true"
rounded
size="x-small"
v-if="(item as Job).status === 'finished'"
style="margin-right: 5px;margin-bottom: 5px;"
@click="restartJob((item as Job).id)">
<v-icon>mdi:mdi-restart</v-icon>
<v-tooltip activator="parent" location="bottom">
Restart
</v-tooltip>
</v-btn>
</template>
</v-data-table-server>
</v-col>
</v-row>
<v-snackbar v-model="jobRestartSnackbar" timeout="2000">
Job restarted as #{{ newJobID }}
</v-snackbar>
</v-container>
</template>

Expand Down Expand Up @@ -179,6 +196,7 @@
export default {
data: () => ({
page: 1,
itemsPerPage: 25,
headers: [
{ title: 'Status', key: 'status', sortable: false },
Expand All @@ -189,15 +207,25 @@
loading: true,
totalItems: 0,
serverItems: [],
jobRestartSnackbar: false,
newJobID: 0,
}),
methods: {
async loadItems (opts: LoadItemsOpts) {
async loadItems () {
this.loading = true;
let url = hostname + `/api/job/list?page=${opts.page}&items_per_page=${opts.itemsPerPage}`;
let url = hostname + `/api/job/list?page=${this.page}&items_per_page=${this.itemsPerPage}`;
let data = (await axios.get(url)).data;
this.totalItems = data.total_items;
this.serverItems = data.items;
this.loading = false;
},
async restartJob (id: number) {
let data = (await axios.post(hostname + `/api/job/restart`, {
job_id: id,
})).data;
this.newJobID = data.job_id;
this.jobRestartSnackbar = true;
await this.loadItems();
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use diesel::r2d2::Pool;
use server::bot::{answer, Command};
use server::recycler::recycler_worker;
use server::routes::{
dashboard_status, job_info, job_list, ping, pipeline_info, pipeline_list, pipeline_new_pr,
worker_info, worker_job_update, worker_list, worker_poll, AppState,
dashboard_status, job_info, job_list, job_restart, ping, pipeline_info, pipeline_list, pipeline_new_pr, worker_info, worker_job_update, worker_list, worker_poll, AppState
};
use server::routes::{pipeline_new, worker_heartbeat};
use server::routes::{pipeline_status, worker_status};
Expand Down Expand Up @@ -67,7 +66,7 @@ async fn main() -> anyhow::Result<()> {
.route("/api/pipeline/info", get(pipeline_info))
.route("/api/job/list", get(job_list))
.route("/api/job/info", get(job_info))
.route("/api/job/info", post(job_restart))
.route("/api/job/restart", post(job_restart))
.route("/api/worker/heartbeat", post(worker_heartbeat))
.route("/api/worker/poll", post(worker_poll))
.route("/api/worker/job_update", post(worker_job_update))
Expand Down Expand Up @@ -103,6 +102,8 @@ async fn main() -> anyhow::Result<()> {
let cors = CorsLayer::new()
// allow `GET` and `POST` when accessing the resource
.allow_methods([Method::GET, Method::POST])
// allow `Content-Type: application/json`
.allow_headers([axum::http::header::CONTENT_TYPE])
// allow requests from any origin
.allow_origin(Any);
app = app.layer(cors);
Expand Down
2 changes: 1 addition & 1 deletion server/src/routes/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,6 @@ pub async fn job_restart(
}

Ok(Json(JobRestartResponse {
job_id: created_job.id,
job_id: new_job.id,
}))
}

0 comments on commit 18098bb

Please sign in to comment.