Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webserver): add jobInfo / triggerJob graphql api #2388

Merged
merged 7 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ expression: "format!(\"{:#?}\", text_chunks)"
"debug!(\"openai-chat request: {:?}\", request);\n let s = stream! {\n let s = match self.client.chat().create_stream(request).await {\n Ok(x) => x,\n Err(e) => {",
"warn!(\"Failed to create completion request {:?}\", e);\n return;\n }\n };",
"for await x in s {\n match x {\n Ok(x) => {\n yield x.choices[0].delta.content.clone().unwrap_or_default();\n },\n Err(e) => {",
"warn!(\"Failed to stream response: {}\", e);\n break;\n }\n };\n }\n };\n\n Ok(Box::pin(s))\n }\n}",
"// Stream finished.\n debug!(\"openai-chat stream finished: {:?}\", e);\n break;\n }\n };\n }\n };\n\n Ok(Box::pin(s))\n }\n}",
]
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ expression: "format!(\"{:#?}\", rust_chunks)"
"{\n Ok(x) => x,\n Err(e) => {\n warn!(\"Failed to create completion request {:?}\", e);\n return;\n }\n };\n\n for await x in s",
"{\n match x",
"{\n Ok(x) => {\n yield x.choices[0].delta.content.clone().unwrap_or_default();\n },\n Err(e) =>",
"{\n warn!(\"Failed to stream response: {}\", e);\n break;\n }\n };\n }\n };\n\n Ok(Box::pin(s))\n }\n}",
"{\n // Stream finished.\n debug!(\"openai-chat stream finished: {:?}\", e);\n break;\n }\n };\n }\n };\n\n Ok(Box::pin(s))\n }\n}",
]
11 changes: 11 additions & 0 deletions ee/tabby-schema/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ type GitRepository {
name: String!
gitUrl: String!
refs: [String!]!
jobInfo: JobInfo!
}

type GrepFile {
Expand Down Expand Up @@ -262,6 +263,13 @@ type InvitationEdge {
cursor: String!
}

type JobInfo {
"Last run of the job."
lastJobRun: JobRun
"The command to submit job run using triggerJobRun mutation."
command: String!
}

type JobRun {
id: ID!
job: String!
Expand Down Expand Up @@ -332,6 +340,8 @@ type Mutation {
updateIntegration(input: UpdateIntegrationInput!): Boolean!
deleteIntegration(id: ID!, kind: IntegrationKind!): Boolean!
updateIntegratedRepositoryActive(id: ID!, active: Boolean!): Boolean!
"Trigger a job run given its command string."
triggerJobRun(command: String!): ID!
}

type NetworkSetting {
Expand Down Expand Up @@ -362,6 +372,7 @@ type ProvidedRepository {
createdAt: DateTime!
updatedAt: DateTime!
refs: [String!]!
jobInfo: JobInfo!
}

type ProvidedRepositoryConnection {
Expand Down
10 changes: 10 additions & 0 deletions ee/tabby-schema/src/schema/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
pub stderr: String,
}

#[derive(Debug, GraphQLObject)]

Check warning on line 25 in ee/tabby-schema/src/schema/job.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-schema/src/schema/job.rs#L25

Added line #L25 was not covered by tests
#[graphql(context = Context)]
pub struct JobInfo {
/// Last run of the job.
pub last_job_run: Option<JobRun>,

/// The command to submit job run using triggerJobRun mutation.
pub command: String,
}

#[derive(Debug, GraphQLObject)]
pub struct JobStats {
pub success: i32,
Expand Down
8 changes: 7 additions & 1 deletion ee/tabby-schema/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
user_event::{UserEvent, UserEventService},
};
use crate::{
env,
bail, env,
juniper::relay::{self, query_async, Connection},
};

Expand Down Expand Up @@ -800,6 +800,12 @@
.await?;
Ok(true)
}

/// Trigger a job run given its command string.
async fn trigger_job_run(ctx: &Context, _command: String) -> Result<ID> {
check_admin(ctx).await?;
bail!("Not implemented")
}

Check warning on line 808 in ee/tabby-schema/src/schema/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-schema/src/schema/mod.rs#L805-L808

Added lines #L805 - L808 were not covered by tests
}

async fn check_analytic_access(ctx: &Context, users: &[ID]) -> Result<(), CoreError> {
Expand Down
3 changes: 3 additions & 0 deletions ee/tabby-schema/src/schema/repository/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use validator::Validate;

use super::RepositoryProvider;
use crate::{
job::JobInfo,
juniper::relay::NodeType,
schema::{Context, Result},
};
Expand All @@ -27,6 +28,8 @@ pub struct GitRepository {
pub name: String,
pub git_url: String,
pub refs: Vec<String>,

pub job_info: JobInfo,
}

impl NodeType for GitRepository {
Expand Down
6 changes: 5 additions & 1 deletion ee/tabby-schema/src/schema/repository/third_party.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use juniper::{GraphQLObject, ID};
use tabby_common::config::RepositoryConfig;

use super::RepositoryProvider;
use crate::{integration::IntegrationKind, juniper::relay::NodeType, schema::Result, Context};
use crate::{
integration::IntegrationKind, job::JobInfo, juniper::relay::NodeType, schema::Result, Context,
};

#[derive(GraphQLObject)]
#[graphql(context = Context)]
Expand All @@ -18,6 +20,8 @@ pub struct ProvidedRepository {
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub refs: Vec<String>,

pub job_info: JobInfo,
}

impl NodeType for ProvidedRepository {
Expand Down
5 changes: 5 additions & 0 deletions ee/tabby-webserver/src/service/repository/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use juniper::ID;
use tabby_common::config::RepositoryConfig;
use tabby_db::{DbConn, RepositoryDAO};
use tabby_schema::{
job::JobInfo,
repository::{GitRepository, GitRepositoryService, Repository, RepositoryProvider},
AsID, AsRowid, Result,
};
Expand Down Expand Up @@ -94,6 +95,10 @@ fn to_git_repository(repo: RepositoryDAO) -> GitRepository {
name: repo.name,
refs: tabby_git::list_refs(&RepositoryConfig::new(&repo.git_url).dir()).unwrap_or_default(),
git_url: repo.git_url,
job_info: JobInfo {
last_job_run: None,
command: "FIXME".to_string(),
},
}
}

Expand Down
6 changes: 6 additions & 0 deletions ee/tabby-webserver/src/service/repository/third_party.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tabby_common::config::RepositoryConfig;
use tabby_db::{DbConn, ProvidedRepositoryDAO};
use tabby_schema::{
integration::{Integration, IntegrationKind, IntegrationService},
job::JobInfo,
repository::{ProvidedRepository, Repository, RepositoryProvider, ThirdPartyRepositoryService},
AsID, AsRowid, DbEnum, Result,
};
Expand Down Expand Up @@ -293,6 +294,11 @@ fn to_provided_repository(value: ProvidedRepositoryDAO) -> ProvidedRepository {
refs: tabby_git::list_refs(&RepositoryConfig::new(&value.git_url).dir())
.unwrap_or_default(),
git_url: value.git_url,

job_info: JobInfo {
last_job_run: None,
command: "FIXME".to_string(),
},
}
}

Expand Down
Loading