Skip to content

Commit 4ae06ac

Browse files
bors[bot]MikailBag
andauthored
Merge #124
124: Rename invocation request to invocation r=MikailBag a=MikailBag bors r+ Co-authored-by: Mikail Bagishov <[email protected]>
2 parents 8fee3d3 + 5caffa4 commit 4ae06ac

File tree

10 files changed

+59
-60
lines changed

10 files changed

+59
-60
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
-- indicies
22
DROP INDEX runs_id_unique_index;
33
-- tables
4-
DROP TABLE invocation_requests;
4+
DROP TABLE invocations;
55
DROP TABLE runs;
66
DROP TABLE users;
77
-- sequences
88
DROP SEQUENCE user_id_seq;
99
DROP SEQUENCE run_id_seq;
10-
DROP SEQUENCE inv_req_id_seq;
10+
DROP SEQUENCE inv_id_seq;
1111
-- types
1212
DROP DOMAIN unsigned_integer;

src/db/migrations/2019-02-13-163254_initial/up.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ CREATE TABLE runs
4141

4242
CREATE UNIQUE INDEX runs_id_unique_index ON runs (id);
4343

44-
CREATE SEQUENCE inv_req_id_seq START WITH 0 MINVALUE 0;
44+
CREATE SEQUENCE inv_id_seq START WITH 0 MINVALUE 0;
4545

4646
-- Invocation requests
4747

48-
CREATE table invocation_requests
48+
CREATE table invocations
4949
(
50-
id unsigned_integer DEFAULT nextval('inv_req_id_seq') UNIQUE PRIMARY KEY NOT NULL,
50+
id unsigned_integer DEFAULT nextval('inv_id_seq') UNIQUE PRIMARY KEY NOT NULL,
5151
-- This is serialized `InvokeTask`. See `invoker-api` for its definition
5252
invoke_task bytea NOT NULL
5353
);

src/db/src/repo.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ pub trait RunsRepo: std::fmt::Debug + Send + Sync {
2121
fn run_select(&self, with_run_id: Option<RunId>, limit: Option<u32>) -> Result<Vec<Run>>;
2222
}
2323

24-
pub trait InvocationRequestsRepo: Send + Sync {
25-
fn inv_req_new(&self, inv_req_data: NewInvocationRequest) -> Result<InvocationRequest>;
26-
fn inv_req_pop(&self) -> Result<Option<InvocationRequest>>;
24+
pub trait InvocationsRepo: Send + Sync {
25+
fn inv_new(&self, inv_req_data: NewInvocation) -> Result<Invocation>;
26+
fn inv_pop(&self) -> Result<Option<Invocation>>;
2727
}
2828

2929
pub trait UsersRepo: Send + Sync {
3030
fn user_new(&self, user_data: NewUser) -> Result<User>;
3131
fn user_try_load_by_login(&self, login: &str) -> Result<Option<User>>;
3232
}
3333

34-
pub trait Repo: RunsRepo + InvocationRequestsRepo + UsersRepo {}
34+
pub trait Repo: RunsRepo + InvocationsRepo + UsersRepo {}

src/db/src/repo/diesel_pg.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InvocationRequestsRepo, Repo, RunsRepo, UsersRepo};
1+
use super::{InvocationsRepo, Repo, RunsRepo, UsersRepo};
22
use crate::schema::*;
33
use anyhow::{Context, Result};
44
use diesel::{prelude::*, r2d2::ConnectionManager};
@@ -64,39 +64,37 @@ mod impl_users {
6464
}
6565
}
6666

67-
mod impl_inv_reqs {
67+
mod impl_invs {
6868
use super::*;
69-
use crate::schema::invocation_requests::dsl::*;
69+
use crate::schema::invocations::dsl::*;
7070

71-
impl InvocationRequestsRepo for DieselRepo {
72-
fn inv_req_new(&self, inv_req_data: NewInvocationRequest) -> Result<InvocationRequest> {
73-
diesel::insert_into(invocation_requests)
74-
.values(&inv_req_data.to_raw()?)
71+
impl InvocationsRepo for DieselRepo {
72+
fn inv_new(&self, inv_data: NewInvocation) -> Result<Invocation> {
73+
diesel::insert_into(invocations)
74+
.values(&inv_data.to_raw()?)
7575
.get_result(&self.conn()?)
76-
.context("failed to load invocation request")
77-
.and_then(|raw| InvocationRequest::from_raw(&raw))
76+
.context("failed to load invocation")
77+
.and_then(|raw| Invocation::from_raw(&raw))
7878
.map_err(Into::into)
7979
}
8080

81-
fn inv_req_pop(&self) -> Result<Option<InvocationRequest>> {
81+
fn inv_pop(&self) -> Result<Option<Invocation>> {
8282
let conn = self.conn()?;
8383
conn.transaction::<_, anyhow::Error, _>(|| {
84-
let waiting_submission = invocation_requests
85-
.limit(1)
86-
.load::<RawInvocationRequest>(&conn)?;
87-
let waiting_submission = waiting_submission.into_iter().next();
88-
match waiting_submission {
84+
let invocation = invocations.limit(1).load::<RawInvocation>(&conn)?;
85+
let invocation = invocation.into_iter().next();
86+
match invocation {
8987
Some(s) => {
90-
diesel::delete(invocation_requests)
88+
diesel::delete(invocations)
9189
.filter(id.eq(s.id))
9290
.execute(&conn)?;
9391

94-
Ok(Some(InvocationRequest::from_raw(&s)?))
92+
Ok(Some(Invocation::from_raw(&s)?))
9593
}
9694
None => Ok(None),
9795
}
9896
})
99-
.context("failed to load invocation request")
97+
.context("failed to extract invocation")
10098
}
10199
}
102100
}

src/db/src/repo/memory.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InvocationRequestsRepo, Repo, RunsRepo, UsersRepo};
1+
use super::{InvocationsRepo, Repo, RunsRepo, UsersRepo};
22
use crate::schema::*;
33
use anyhow::{bail, Result};
44
use std::{convert::TryFrom, sync::Mutex};
@@ -7,7 +7,7 @@ use std::{convert::TryFrom, sync::Mutex};
77
struct Data {
88
// None if run was deleted
99
runs: Vec<Option<Run>>,
10-
inv_reqs: Vec<InvocationRequest>,
10+
invs: Vec<Invocation>,
1111
users: Vec<User>,
1212
}
1313

@@ -118,21 +118,21 @@ impl RunsRepo for MemoryRepo {
118118
}
119119
}
120120

121-
impl InvocationRequestsRepo for MemoryRepo {
122-
fn inv_req_new(&self, inv_req_data: NewInvocationRequest) -> Result<InvocationRequest> {
121+
impl InvocationsRepo for MemoryRepo {
122+
fn inv_new(&self, inv_data: NewInvocation) -> Result<Invocation> {
123123
let mut data = self.conn.lock().unwrap();
124-
let inv_req_id = data.inv_reqs.len() as InvocationRequestId;
125-
let inv_req = InvocationRequest {
126-
id: inv_req_id,
127-
invoke_task: inv_req_data.invoke_task,
124+
let inv_id = data.invs.len() as InvocationId;
125+
let inv = Invocation {
126+
id: inv_id,
127+
invoke_task: inv_data.invoke_task,
128128
};
129-
data.inv_reqs.push(inv_req.clone());
130-
Ok(inv_req)
129+
data.invs.push(inv.clone());
130+
Ok(inv)
131131
}
132132

133-
fn inv_req_pop(&self) -> Result<Option<InvocationRequest>> {
133+
fn inv_pop(&self) -> Result<Option<Invocation>> {
134134
let mut data = self.conn.lock().unwrap();
135-
Ok(data.inv_reqs.pop())
135+
Ok(data.invs.pop())
136136
}
137137
}
138138

src/db/src/schema.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::{Context, Result};
22
use serde::{Deserialize, Serialize};
33

44
pub type RunId = i32;
5-
pub type InvocationRequestId = i32;
5+
pub type InvocationId = i32;
66
pub type UserId = uuid::Uuid;
77
pub type ProblemId = String;
88

@@ -42,25 +42,25 @@ pub struct RunPatch {
4242
}
4343

4444
#[derive(Queryable, Debug, Clone, Serialize, Deserialize)]
45-
pub(crate) struct RawInvocationRequest {
46-
pub(crate) id: InvocationRequestId,
45+
pub(crate) struct RawInvocation {
46+
pub(crate) id: InvocationId,
4747
pub(crate) invoke_task: Vec<u8>,
4848
}
4949

5050
#[derive(Insertable)]
51-
#[table_name = "invocation_requests"]
52-
pub(crate) struct RawNewInvocationRequest {
51+
#[table_name = "invocations"]
52+
pub(crate) struct RawNewInvocation {
5353
pub(crate) invoke_task: Vec<u8>,
5454
}
5555

5656
#[derive(Debug, Clone)]
57-
pub struct InvocationRequest {
58-
pub id: InvocationRequestId,
57+
pub struct Invocation {
58+
pub id: InvocationId,
5959
pub invoke_task: invoker_api::InvokeTask,
6060
}
6161

62-
impl InvocationRequest {
63-
pub(crate) fn from_raw(raw: &RawInvocationRequest) -> Result<Self> {
62+
impl Invocation {
63+
pub(crate) fn from_raw(raw: &RawInvocation) -> Result<Self> {
6464
Ok(Self {
6565
id: raw.id,
6666
invoke_task: bincode::deserialize(&raw.invoke_task)
@@ -69,16 +69,16 @@ impl InvocationRequest {
6969
}
7070
}
7171

72-
impl NewInvocationRequest {
73-
pub(crate) fn to_raw(&self) -> Result<RawNewInvocationRequest> {
74-
Ok(RawNewInvocationRequest {
72+
impl NewInvocation {
73+
pub(crate) fn to_raw(&self) -> Result<RawNewInvocation> {
74+
Ok(RawNewInvocation {
7575
invoke_task: bincode::serialize(&self.invoke_task)
7676
.context("failed to serialize InvokeTask")?,
7777
})
7878
}
7979
}
8080

81-
pub struct NewInvocationRequest {
81+
pub struct NewInvocation {
8282
pub invoke_task: invoker_api::InvokeTask,
8383
}
8484

src/db/src/schema_raw.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
table! {
22
use super::*;
33

4-
invocation_requests (id) {
4+
invocations (id) {
55
id -> Int4,
66
invoke_task -> Bytea,
77
}
@@ -36,7 +36,7 @@ table! {
3636
joinable!(runs -> users (user_id));
3737

3838
allow_tables_to_appear_in_same_query!(
39-
invocation_requests,
39+
invocations,
4040
runs,
4141
users,
4242
);

src/frontend-engine/src/gql_server/runs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub(super) fn submit_simple(
207207
problem: schema::ProblemId,
208208
contest: schema::ContestId,
209209
) -> ApiResult<Run> {
210-
use db::schema::NewInvocationRequest;
210+
use db::schema::NewInvocation;
211211
let toolchain = ctx.cfg.toolchains.iter().find(|t| t.name == toolchain);
212212
let toolchain = match toolchain {
213213
Some(tc) => tc.clone(),
@@ -260,9 +260,9 @@ pub(super) fn submit_simple(
260260
status_update_callback: get_lsu_webhook_url(ctx, run.id as u32),
261261
};
262262

263-
let new_inv_req = NewInvocationRequest { invoke_task };
263+
let new_inv = NewInvocation { invoke_task };
264264

265-
ctx.db.inv_req_new(new_inv_req).internal(ctx)?;
265+
ctx.db.inv_new(new_inv).internal(ctx)?;
266266

267267
Ok(describe_run(&run))
268268
}

src/invoker/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod valuer;
1212
use crate::{invoke_context::MainInvokeContext, invoke_env::InvokeEnv};
1313
use anyhow::{bail, Context};
1414
use cfg_if::cfg_if;
15-
use db::schema::InvocationRequest;
15+
use db::schema::Invocation;
1616
use invoker::Invoker;
1717
use invoker_api::InvokeTask;
1818
use slog_scope::{debug, error};
@@ -107,9 +107,9 @@ impl Server {
107107
}
108108

109109
fn try_get_task(&self) -> Option<InvokeTask> {
110-
let res: Option<InvocationRequest> = self
110+
let res: Option<Invocation> = self
111111
.db_conn
112-
.inv_req_pop() // TODO handle error
112+
.inv_pop() // TODO handle error
113113
.ok()
114114
.flatten();
115115

0 commit comments

Comments
 (0)