From 513761e025b16ee3101055c6c7342679ef171224 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Tue, 11 Jun 2024 20:31:23 +0800 Subject: [PATCH 1/7] feat(webserver): add jobInfo / triggerJob graphql api --- ee/tabby-schema/src/schema/job.rs | 10 ++++++++++ ee/tabby-schema/src/schema/mod.rs | 7 ++++++- ee/tabby-schema/src/schema/repository/git.rs | 3 +++ ee/tabby-schema/src/schema/repository/third_party.rs | 6 +++++- ee/tabby-webserver/src/service/repository/git.rs | 5 +++++ .../src/service/repository/third_party.rs | 6 ++++++ 6 files changed, 35 insertions(+), 2 deletions(-) diff --git a/ee/tabby-schema/src/schema/job.rs b/ee/tabby-schema/src/schema/job.rs index 0d116af4881b..09efb987ef4e 100644 --- a/ee/tabby-schema/src/schema/job.rs +++ b/ee/tabby-schema/src/schema/job.rs @@ -22,6 +22,16 @@ pub struct JobRun { pub stderr: String, } +#[derive(Debug, GraphQLObject)] +#[graphql(context = Context)] +pub struct JobInfo { + /// Last run of the job. + pub last_run: Option, + + /// The command to submit job run using triggerJob mutation. + pub command: String, +} + #[derive(Debug, GraphQLObject)] pub struct JobStats { pub success: i32, diff --git a/ee/tabby-schema/src/schema/mod.rs b/ee/tabby-schema/src/schema/mod.rs index 7ee68c6e3d41..e860c2140c7f 100644 --- a/ee/tabby-schema/src/schema/mod.rs +++ b/ee/tabby-schema/src/schema/mod.rs @@ -48,7 +48,7 @@ use self::{ user_event::{UserEvent, UserEventService}, }; use crate::{ - env, + bail, env, juniper::relay::{self, query_async, Connection}, }; @@ -800,6 +800,11 @@ impl Mutation { .await?; Ok(true) } + + async fn trigger_job(ctx: &Context, _command: String) -> Result { + check_admin(ctx).await?; + bail!("Not implemented") + } } async fn check_analytic_access(ctx: &Context, users: &[ID]) -> Result<(), CoreError> { diff --git a/ee/tabby-schema/src/schema/repository/git.rs b/ee/tabby-schema/src/schema/repository/git.rs index 3f529de6ee49..e8b6bb1d7d92 100644 --- a/ee/tabby-schema/src/schema/repository/git.rs +++ b/ee/tabby-schema/src/schema/repository/git.rs @@ -4,6 +4,7 @@ use validator::Validate; use super::RepositoryProvider; use crate::{ + job::JobInfo, juniper::relay::NodeType, schema::{Context, Result}, }; @@ -27,6 +28,8 @@ pub struct GitRepository { pub name: String, pub git_url: String, pub refs: Vec, + + pub job_info: JobInfo, } impl NodeType for GitRepository { diff --git a/ee/tabby-schema/src/schema/repository/third_party.rs b/ee/tabby-schema/src/schema/repository/third_party.rs index 0931f607a54f..878a3b263509 100644 --- a/ee/tabby-schema/src/schema/repository/third_party.rs +++ b/ee/tabby-schema/src/schema/repository/third_party.rs @@ -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)] @@ -18,6 +20,8 @@ pub struct ProvidedRepository { pub created_at: DateTime, pub updated_at: DateTime, pub refs: Vec, + + pub job_info: JobInfo, } impl NodeType for ProvidedRepository { diff --git a/ee/tabby-webserver/src/service/repository/git.rs b/ee/tabby-webserver/src/service/repository/git.rs index 7c511685d25e..d2ac825b0971 100644 --- a/ee/tabby-webserver/src/service/repository/git.rs +++ b/ee/tabby-webserver/src/service/repository/git.rs @@ -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, }; @@ -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_run: None, + command: "FIXME".to_string(), + }, } } diff --git a/ee/tabby-webserver/src/service/repository/third_party.rs b/ee/tabby-webserver/src/service/repository/third_party.rs index 3d6d3835197c..28b0d745d918 100644 --- a/ee/tabby-webserver/src/service/repository/third_party.rs +++ b/ee/tabby-webserver/src/service/repository/third_party.rs @@ -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, }; @@ -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_run: None, + command: "FIXME".to_string(), + }, } } From 1f4825e6483843012f66276f97753ca1186dd5da Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Tue, 11 Jun 2024 20:32:42 +0800 Subject: [PATCH 2/7] update --- ee/tabby-schema/graphql/schema.graphql | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ee/tabby-schema/graphql/schema.graphql b/ee/tabby-schema/graphql/schema.graphql index e20598a77a41..ef5b090a7566 100644 --- a/ee/tabby-schema/graphql/schema.graphql +++ b/ee/tabby-schema/graphql/schema.graphql @@ -196,6 +196,7 @@ type GitRepository { name: String! gitUrl: String! refs: [String!]! + jobInfo: JobInfo! } type GrepFile { @@ -262,6 +263,13 @@ type InvitationEdge { cursor: String! } +type JobInfo { + "Last run of the job." + lastRun: JobRun + "The command to submit job run using triggerJob mutation." + command: String! +} + type JobRun { id: ID! job: String! @@ -332,6 +340,7 @@ type Mutation { updateIntegration(input: UpdateIntegrationInput!): Boolean! deleteIntegration(id: ID!, kind: IntegrationKind!): Boolean! updateIntegratedRepositoryActive(id: ID!, active: Boolean!): Boolean! + triggerJob(command: String!): ID! } type NetworkSetting { @@ -362,6 +371,7 @@ type ProvidedRepository { createdAt: DateTime! updatedAt: DateTime! refs: [String!]! + jobInfo: JobInfo! } type ProvidedRepositoryConnection { From 0981d1c29e4fc622bec174a77d0c055b404f3105 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Tue, 11 Jun 2024 20:35:07 +0800 Subject: [PATCH 3/7] update --- ee/tabby-schema/src/schema/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ee/tabby-schema/src/schema/mod.rs b/ee/tabby-schema/src/schema/mod.rs index e860c2140c7f..6afeded4faf3 100644 --- a/ee/tabby-schema/src/schema/mod.rs +++ b/ee/tabby-schema/src/schema/mod.rs @@ -801,7 +801,8 @@ impl Mutation { Ok(true) } - async fn trigger_job(ctx: &Context, _command: String) -> Result { + /// Trigger a job run given its command string. + async fn trigger_job_run(ctx: &Context, _command: String) -> Result { check_admin(ctx).await?; bail!("Not implemented") } From ea152d6b2e1d2013328019d4a9c9428dd403c0d6 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Tue, 11 Jun 2024 20:35:20 +0800 Subject: [PATCH 4/7] update --- ee/tabby-schema/graphql/schema.graphql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ee/tabby-schema/graphql/schema.graphql b/ee/tabby-schema/graphql/schema.graphql index ef5b090a7566..93fd74770a91 100644 --- a/ee/tabby-schema/graphql/schema.graphql +++ b/ee/tabby-schema/graphql/schema.graphql @@ -340,7 +340,8 @@ type Mutation { updateIntegration(input: UpdateIntegrationInput!): Boolean! deleteIntegration(id: ID!, kind: IntegrationKind!): Boolean! updateIntegratedRepositoryActive(id: ID!, active: Boolean!): Boolean! - triggerJob(command: String!): ID! + "Trigger a job run given its command string." + triggerJobRun(command: String!): ID! } type NetworkSetting { From ef86c5aa052baf779c342589c7ddde3d23782958 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Tue, 11 Jun 2024 20:36:21 +0800 Subject: [PATCH 5/7] update --- ee/tabby-schema/graphql/schema.graphql | 4 ++-- ee/tabby-schema/src/schema/job.rs | 4 ++-- ee/tabby-webserver/src/service/repository/git.rs | 2 +- ee/tabby-webserver/src/service/repository/third_party.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ee/tabby-schema/graphql/schema.graphql b/ee/tabby-schema/graphql/schema.graphql index 93fd74770a91..b04f298b60d3 100644 --- a/ee/tabby-schema/graphql/schema.graphql +++ b/ee/tabby-schema/graphql/schema.graphql @@ -265,8 +265,8 @@ type InvitationEdge { type JobInfo { "Last run of the job." - lastRun: JobRun - "The command to submit job run using triggerJob mutation." + lastJobRun: JobRun + "The command to submit job run using triggerJobRun mutation." command: String! } diff --git a/ee/tabby-schema/src/schema/job.rs b/ee/tabby-schema/src/schema/job.rs index 09efb987ef4e..fc17fd6cbca2 100644 --- a/ee/tabby-schema/src/schema/job.rs +++ b/ee/tabby-schema/src/schema/job.rs @@ -26,9 +26,9 @@ pub struct JobRun { #[graphql(context = Context)] pub struct JobInfo { /// Last run of the job. - pub last_run: Option, + pub last_job_run: Option, - /// The command to submit job run using triggerJob mutation. + /// The command to submit job run using triggerJobRun mutation. pub command: String, } diff --git a/ee/tabby-webserver/src/service/repository/git.rs b/ee/tabby-webserver/src/service/repository/git.rs index d2ac825b0971..123631d1fe08 100644 --- a/ee/tabby-webserver/src/service/repository/git.rs +++ b/ee/tabby-webserver/src/service/repository/git.rs @@ -96,7 +96,7 @@ fn to_git_repository(repo: RepositoryDAO) -> GitRepository { refs: tabby_git::list_refs(&RepositoryConfig::new(&repo.git_url).dir()).unwrap_or_default(), git_url: repo.git_url, job_info: JobInfo { - last_run: None, + last_job_run: None, command: "FIXME".to_string(), }, } diff --git a/ee/tabby-webserver/src/service/repository/third_party.rs b/ee/tabby-webserver/src/service/repository/third_party.rs index 28b0d745d918..65d56efc47db 100644 --- a/ee/tabby-webserver/src/service/repository/third_party.rs +++ b/ee/tabby-webserver/src/service/repository/third_party.rs @@ -296,7 +296,7 @@ fn to_provided_repository(value: ProvidedRepositoryDAO) -> ProvidedRepository { git_url: value.git_url, job_info: JobInfo { - last_run: None, + last_job_run: None, command: "FIXME".to_string(), }, } From 1efd4459317491af0928d6aab8704d4feee5f595 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Tue, 11 Jun 2024 21:02:21 +0800 Subject: [PATCH 6/7] update --- .../tabby_scheduler__code__index__tests__code_splitter.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tabby-scheduler/src/code/snapshots/tabby_scheduler__code__index__tests__code_splitter.snap b/crates/tabby-scheduler/src/code/snapshots/tabby_scheduler__code__index__tests__code_splitter.snap index f009da708015..d060e07a819f 100644 --- a/crates/tabby-scheduler/src/code/snapshots/tabby_scheduler__code__index__tests__code_splitter.snap +++ b/crates/tabby-scheduler/src/code/snapshots/tabby_scheduler__code__index__tests__code_splitter.snap @@ -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}", ] From 0015064273219d14b0f5610276dec5b164667022 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Tue, 11 Jun 2024 23:03:08 +0800 Subject: [PATCH 7/7] update --- .../tabby_scheduler__code__index__tests__code_splitter-2.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tabby-scheduler/src/code/snapshots/tabby_scheduler__code__index__tests__code_splitter-2.snap b/crates/tabby-scheduler/src/code/snapshots/tabby_scheduler__code__index__tests__code_splitter-2.snap index 2f6d77fbdb36..9f9b56d00a15 100644 --- a/crates/tabby-scheduler/src/code/snapshots/tabby_scheduler__code__index__tests__code_splitter-2.snap +++ b/crates/tabby-scheduler/src/code/snapshots/tabby_scheduler__code__index__tests__code_splitter-2.snap @@ -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}", ]