-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add job command to start sessions as batch jobs #68
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0907dec
skeleton command for job start
eikek 7949583
start a non-interactive session
eikek 49e0305
stop a session
eikek 463c81f
start listing jobs
eikek a8207ea
list logs of jobs
eikek 00638da
react better on failure responses, remove debug flag in httpclient
eikek 88634d4
clippy
eikek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| pub mod list; | ||
| pub mod logs; | ||
| pub mod start; | ||
| pub mod stop; | ||
|
|
||
| use super::Context; | ||
| use clap::Parser; | ||
| use snafu::{ResultExt, Snafu}; | ||
|
|
||
| #[derive(Debug, Snafu)] | ||
| pub enum Error { | ||
| #[snafu(display("Error starting job: {}", source))] | ||
| Start { source: start::Error }, | ||
|
|
||
| #[snafu(display("Error stopping job: {}", source))] | ||
| Stop { source: stop::Error }, | ||
|
|
||
| #[snafu(display("Error listing jobs: {}", source))] | ||
| List { source: list::Error }, | ||
|
|
||
| #[snafu(display("Error getting logs: {}", source))] | ||
| Logs { source: logs::Error }, | ||
| } | ||
|
|
||
| /// Sub command for managing projects | ||
| #[derive(Parser, Debug)] | ||
| pub struct Input { | ||
| #[command(subcommand)] | ||
| pub subcmd: JobCommand, | ||
| } | ||
|
|
||
| impl Input { | ||
| pub async fn exec(&self, ctx: Context) -> Result<(), Error> { | ||
| match &self.subcmd { | ||
| JobCommand::Start(input) => input.exec(ctx).await.context(StartSnafu), | ||
| JobCommand::Stop(input) => input.exec(ctx).await.context(StopSnafu), | ||
| JobCommand::List(input) => input.exec(ctx).await.context(ListSnafu), | ||
| JobCommand::Logs(input) => input.exec(ctx).await.context(LogsSnafu), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Parser, Debug)] | ||
| pub enum JobCommand { | ||
| #[command()] | ||
| Start(start::Input), | ||
|
|
||
| #[command()] | ||
| Stop(stop::Input), | ||
|
|
||
| #[command()] | ||
| List(list::Input), | ||
|
|
||
| #[command()] | ||
| Logs(logs::Input), | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| use super::Context; | ||
| use crate::{ | ||
| cli::sink::Error as SinkError, | ||
| httpclient::{self, data::SessionMode}, | ||
| }; | ||
|
|
||
| use clap::Parser; | ||
|
|
||
| use snafu::{ResultExt, Snafu}; | ||
|
|
||
| /// Listing jobs. | ||
| /// | ||
| /// List currently running jobs. | ||
| #[derive(Parser, Debug)] | ||
| pub struct Input {} | ||
|
|
||
| #[derive(Debug, Snafu)] | ||
| pub enum Error { | ||
| #[snafu(display("Error writing data: {}", source))] | ||
| WriteResult { source: SinkError }, | ||
|
|
||
| #[snafu(display("Http error: {}", source))] | ||
| HttpClient { source: httpclient::Error }, | ||
| } | ||
|
|
||
| impl Input { | ||
| pub async fn exec(&self, ctx: Context) -> Result<(), Error> { | ||
| let result = ctx | ||
| .client | ||
| .list_sessions(Some(SessionMode::NonInteractive)) | ||
| .await | ||
| .context(HttpClientSnafu)?; | ||
|
|
||
| ctx.write_result(&result).await.context(WriteResultSnafu) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| use super::Context; | ||
| use crate::{cli::sink::Error as SinkError, data::simple_message::SimpleMessage, httpclient}; | ||
|
|
||
| use clap::{Parser, ValueHint}; | ||
|
|
||
| use snafu::{ResultExt, Snafu}; | ||
|
|
||
| /// Listing logs of a jobs. | ||
| /// | ||
| /// List the logs of a job. | ||
| #[derive(Parser, Debug)] | ||
| pub struct Input { | ||
| #[arg(value_hint=ValueHint::Other)] | ||
| pub job_id: String, | ||
| } | ||
|
|
||
| #[derive(Debug, Snafu)] | ||
| pub enum Error { | ||
| #[snafu(display("Error writing data: {}", source))] | ||
| WriteResult { source: SinkError }, | ||
|
|
||
| #[snafu(display("Http error: {}", source))] | ||
| HttpClient { source: httpclient::Error }, | ||
| } | ||
|
|
||
| impl Input { | ||
| pub async fn exec(&self, ctx: Context) -> Result<(), Error> { | ||
| let result = ctx | ||
| .client | ||
| .session_logs(&self.job_id) | ||
| .await | ||
| .context(HttpClientSnafu)?; | ||
|
|
||
| if let Some(lines) = result.0.get("amalthea-session") { | ||
| ctx.write_result(&SimpleMessage { | ||
| message: lines.to_string(), | ||
| }) | ||
| .await | ||
| .context(WriteResultSnafu) | ||
| } else { | ||
| ctx.write_result(&SimpleMessage { | ||
| message: "No logs available.".to_string(), | ||
| }) | ||
| .await | ||
| .context(WriteResultSnafu) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| use crate::httpclient::{self, data::SessionStartRequest}; | ||
|
|
||
| use super::Context; | ||
| use crate::cli::sink::Error as SinkError; | ||
|
|
||
| use clap::{Parser, ValueHint}; | ||
| use ulid::Ulid; | ||
|
|
||
| use snafu::{ResultExt, Snafu}; | ||
|
|
||
| /// Start a job. | ||
| /// | ||
| /// Starts a non-interactive session using a pre-configured session launcher. | ||
| #[derive(Parser, Debug)] | ||
| pub struct Input { | ||
| /// The launcher to use for launching the job. | ||
| #[arg(value_hint=ValueHint::Other)] | ||
| pub launcher: Ulid, | ||
| } | ||
|
|
||
| #[derive(Debug, Snafu)] | ||
| pub enum Error { | ||
| #[snafu(display("Error writing data: {}", source))] | ||
| WriteResult { source: SinkError }, | ||
|
|
||
| #[snafu(display("Http error: {}", source))] | ||
| HttpClient { source: httpclient::Error }, | ||
| } | ||
|
|
||
| impl Input { | ||
| pub async fn exec(&self, ctx: Context) -> Result<(), Error> { | ||
| let req = SessionStartRequest { | ||
| launcher_id: self.launcher.to_string(), | ||
| session_type: "non-interactive".into(), | ||
| }; | ||
| let result = ctx | ||
| .client | ||
| .start_session(req) | ||
| .await | ||
| .context(HttpClientSnafu)?; | ||
|
|
||
| ctx.write_result(&result).await.context(WriteResultSnafu) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| use crate::{data::simple_message::SimpleMessage, httpclient}; | ||
|
|
||
| use super::Context; | ||
| use crate::cli::sink::Error as SinkError; | ||
|
|
||
| use clap::{Parser, ValueHint}; | ||
|
|
||
| use snafu::{ResultExt, Snafu}; | ||
|
|
||
| /// Stop a job. | ||
| /// | ||
| /// Stop a running non-interactive session. | ||
| #[derive(Parser, Debug)] | ||
| pub struct Input { | ||
| /// The launcher to use for launching the job. | ||
| #[arg(value_hint=ValueHint::Other)] | ||
| pub job_id: String, | ||
| } | ||
|
|
||
| #[derive(Debug, Snafu)] | ||
| pub enum Error { | ||
| #[snafu(display("Error writing data: {}", source))] | ||
| WriteResult { source: SinkError }, | ||
|
|
||
| #[snafu(display("Http error: {}", source))] | ||
| HttpClient { source: httpclient::Error }, | ||
| } | ||
|
|
||
| impl Input { | ||
| pub async fn exec(&self, ctx: Context) -> Result<(), Error> { | ||
| ctx.client | ||
| .stop_session(&self.job_id) | ||
| .await | ||
| .context(HttpClientSnafu)?; | ||
| ctx.write_result(&SimpleMessage { | ||
| message: "Job is being removed.".into(), | ||
| }) | ||
| .await | ||
| .context(WriteResultSnafu) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can live with this for now but in the future we should add an optional flag to filter by project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that should be done! Currently I don't think there is an option in the API to filter by project. The session response contains the project id, but perhaps we want some filtering based on the project name. If so, making this more efficient probably means to enhance the api. I thought filtering by project id at the client is maybe not so useful, so I left it (for now one could pipe the output to jq and do the filtering… I know :-))