-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
156 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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 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 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,52 @@ | ||
{ | ||
"name": "example", | ||
"version": "v1", | ||
"dag": [ | ||
{ | ||
"name": "dummy-in", | ||
"spec": { | ||
"image": "jz-action/dummy_in:latest", | ||
"command": "/dummy_in", | ||
"args": [ | ||
"--log-level=debug" | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "copy-in-place", | ||
"node_type": "ComputeUnit", | ||
"dependency": [ | ||
"dummy-in" | ||
], | ||
"spec": { | ||
"image": "jz-action/copy_in_place:latest", | ||
"command": "/copy_in_place", | ||
"replicas": 3, | ||
"args": [ | ||
"--log-level=debug" | ||
] | ||
}, | ||
"channel": { | ||
"cache_type": "Memory" | ||
} | ||
}, | ||
{ | ||
"name": "dummy-out", | ||
"node_type": "ComputeUnit", | ||
"dependency": [ | ||
"copy-in-place" | ||
], | ||
"spec": { | ||
"image": "jz-action/dummy_out:latest", | ||
"command": "/dummy_out", | ||
"replicas": 3, | ||
"args": [ | ||
"--log-level=debug" | ||
] | ||
}, | ||
"channel": { | ||
"cache_type": "Memory" | ||
} | ||
} | ||
] | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1 +1,28 @@ | ||
pub mod job; | ||
mod job; | ||
|
||
use awc::Client; | ||
use anyhow::Result; | ||
use job::JobClient; | ||
|
||
#[derive(Clone)] | ||
pub struct JzFlowClient { | ||
client: Client, | ||
base_uri: String, | ||
} | ||
|
||
impl JzFlowClient { | ||
pub fn new(base_uri: &str) -> Result<Self> { | ||
let client = Client::builder() | ||
.add_default_header(("Content-Type", "application/json")) | ||
.finish(); | ||
let base_uri = base_uri.to_string() + "/api/v1"; | ||
Ok(JzFlowClient { client, base_uri }) | ||
} | ||
|
||
pub fn job(&self) -> JobClient { | ||
JobClient { | ||
client: self.client.clone(), | ||
base_uri: self.base_uri.clone(), | ||
} | ||
} | ||
} |
This file contains 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 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 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 |
---|---|---|
@@ -1,16 +1,48 @@ | ||
use crate::global::GlobalOptions; | ||
use anyhow::Result; | ||
use clap::Args; | ||
use chrono::Utc; | ||
use clap::{Args, Parser, Subcommand}; | ||
use tokio::fs; | ||
use jz_action::{api::client::JzFlowClient, core::db::Job, dag::Dag}; | ||
|
||
#[derive(Debug, Parser)] | ||
pub(super) enum JobCommands { | ||
/// Adds files to myapp | ||
Create(JobCreateArgs), | ||
} | ||
|
||
pub(super) async fn run_job_subcommand(global_opts: GlobalOptions ,command: JobCommands) ->Result<()> { | ||
match command { | ||
JobCommands::Create(args) => create_job(global_opts, args).await, | ||
} | ||
} | ||
|
||
|
||
#[derive(Debug, Args)] | ||
pub(super) struct JobCreateArgs { | ||
#[arg(long)] | ||
#[arg(long, help="job name, must be unique")] | ||
pub(super) name: String, | ||
|
||
#[arg(long, help = "dag pipline definition")] | ||
pub(super) path: String, | ||
} | ||
|
||
pub(super) async fn run_backend(global_opts: GlobalOptions, args: JobCreateArgs) -> Result<()> { | ||
pub(super) async fn create_job(global_opts: GlobalOptions, args: JobCreateArgs) -> Result<()> { | ||
let client = JzFlowClient::new(&global_opts.listen)?.job(); | ||
let dag_config = fs::read_to_string(&args.path).await?; | ||
let _ = Dag::from_json(dag_config.as_str())?; | ||
let tm = Utc::now().timestamp(); | ||
let job = Job{ | ||
name: args.name.clone(), | ||
graph_json: dag_config, | ||
created_at: tm, | ||
updated_at: tm, | ||
..Default::default() | ||
}; | ||
|
||
println!("aaaaad"); | ||
let created_job = client.create(&job).await?; | ||
|
||
println!("Create job successfully, job ID: {}", created_job.id.to_string()); | ||
Ok(()) | ||
} |
This file contains 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 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 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 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 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