Skip to content

Commit

Permalink
chore: Rename playbook task and status names
Browse files Browse the repository at this point in the history
  • Loading branch information
wangeguo committed Jan 24, 2024
1 parent 496626f commit cb61356
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 49 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.8.3"
version = "0.8.4"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/amphitheatre-app/amphitheatre"
Expand Down
2 changes: 1 addition & 1 deletion controllers/src/playbook_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub async fn reconcile(playbook: Arc<Playbook>, ctx: Arc<Context>) -> Result<Act
Event::Cleanup(playbook) => {
info!("Cleanup playbook {}", playbook.name_any());
workflow.set_context(playbook.clone());
workflow.transition(Box::new(amp_workflow::playbook::EndingState));
workflow.transition(Box::new(amp_workflow::playbook::CleanupState));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ use async_trait::async_trait;
use kube::ResourceExt;
use tracing::info;

pub struct EndingState;
pub struct CleanupState;

#[async_trait]
impl State<Playbook> for EndingState {
impl State<Playbook> for CleanupState {
/// Execute the logic for the ending state
async fn handle(&self, ctx: &Context<Playbook>) -> Option<Box<dyn State<Playbook>>> {
// Check if EndTask should be executed
let task = EndTask::new();
let task = CleanupTask::new();
if task.matches(ctx) {
if let Err(err) = task.execute(ctx).await {
// Handle error, maybe log it
Expand All @@ -38,12 +38,12 @@ impl State<Playbook> for EndingState {
}
}

pub struct EndTask;
pub struct CleanupTask;

#[async_trait]
impl Task<Playbook> for EndTask {
impl Task<Playbook> for CleanupTask {
fn new() -> Self {
EndTask
CleanupTask
}

fn matches(&self, _: &Context<Playbook>) -> bool {
Expand All @@ -57,7 +57,7 @@ impl Task<Playbook> for EndTask {
}
}

impl EndTask {
impl CleanupTask {
async fn cleanup(&self, ctx: &Context<Playbook>, playbook: &Playbook) -> Result<()> {
// Try to delete the NATS stream for this playbook if it exists.
if ctx.jetstream.delete_stream(playbook.name_any()).await.is_ok() {
Expand Down
4 changes: 2 additions & 2 deletions workflow/src/playbook/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use async_trait::async_trait;
use kube::ResourceExt;
use tracing::{debug, error, info};

use super::SchedulingState;
use super::ResolvingState;

pub struct InitialState;

Expand All @@ -41,7 +41,7 @@ impl State<Playbook> for InitialState {
}

// Transition to the next state if needed
Some(Box::new(SchedulingState))
Some(Box::new(ResolvingState))
}
}

Expand Down
18 changes: 9 additions & 9 deletions workflow/src/playbook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ mod init;
pub use init::InitTask;
pub use init::InitialState;

mod schedule;
pub use schedule::ScheduleTask;
pub use schedule::SchedulingState;
mod resolve;
pub use resolve::ResolveTask;
pub use resolve::ResolvingState;

mod perform;
pub use perform::PerformTask;
pub use perform::PerformingState;
mod run;
pub use run::RunTask;
pub use run::RunningState;

mod end;
pub use end::EndTask;
pub use end::EndingState;
mod cleanup;
pub use cleanup::CleanupState;
pub use cleanup::CleanupTask;
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,47 @@ use async_trait::async_trait;
use std::collections::HashSet;
use tracing::{debug, info};

use super::PerformingState;
use super::RunningState;

pub struct SchedulingState;
pub struct ResolvingState;

#[async_trait]
impl State<Playbook> for SchedulingState {
impl State<Playbook> for ResolvingState {
/// Execute the logic for the scheduling state
async fn handle(&self, ctx: &Context<Playbook>) -> Option<Box<dyn State<Playbook>>> {
// Check if ScheduleTask should be executed
let task = ScheduleTask::new();
// Check if ResolveTask should be executed
let task = ResolveTask::new();
if task.matches(ctx) {
if let Err(err) = task.execute(ctx).await {
// Handle error, maybe log it
println!("Error during ScheduleTask execution: {}", err);
println!("Error during ResolveTask execution: {}", err);
}
}

// Transition to the next state if needed
Some(Box::new(PerformingState))
Some(Box::new(RunningState))
}
}

pub struct ScheduleTask;
pub struct ResolveTask;

#[async_trait]
impl Task<Playbook> for ScheduleTask {
impl Task<Playbook> for ResolveTask {
fn new() -> Self {
ScheduleTask
ResolveTask
}

fn matches(&self, ctx: &Context<Playbook>) -> bool {
ctx.object.status.as_ref().is_some_and(|status| status.resolving())
}

// Execute the task logic for InitTask using shared data
// Execute the task logic for ResolveTask using shared data
async fn execute(&self, ctx: &Context<Playbook>) -> Result<()> {
self.resolve(ctx, &ctx.object).await
}
}

impl ScheduleTask {
impl ResolveTask {
async fn resolve(&self, ctx: &Context<Playbook>, playbook: &Playbook) -> Result<()> {
// Check if there are any repositories to fetch
//
Expand Down
20 changes: 10 additions & 10 deletions workflow/src/playbook/perform.rs → workflow/src/playbook/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ use amp_resources::actor;
use async_trait::async_trait;
use tracing::{error, info};

pub struct PerformingState;
pub struct RunningState;

#[async_trait]
impl State<Playbook> for PerformingState {
/// Execute the logic for the performing state
impl State<Playbook> for RunningState {
/// Execute the logic for the Running state
async fn handle(&self, ctx: &Context<Playbook>) -> Option<Box<dyn State<Playbook>>> {
// Check if PerformTask should be executed
let task = PerformTask::new();
// Check if RunTask should be executed
let task = RunTask::new();
if task.matches(ctx) {
if let Err(err) = task.execute(ctx).await {
// Handle error, maybe log it
println!("Error during PerformTask execution: {}", err);
println!("Error during RunTask execution: {}", err);
}
}

None // No transition, wait for next state
}
}

pub struct PerformTask;
pub struct RunTask;

#[async_trait]
impl Task<Playbook> for PerformTask {
impl Task<Playbook> for RunTask {
fn new() -> Self {
PerformTask
RunTask
}

fn matches(&self, ctx: &Context<Playbook>) -> bool {
Expand All @@ -56,7 +56,7 @@ impl Task<Playbook> for PerformTask {
}
}

impl PerformTask {
impl RunTask {
async fn run(&self, ctx: &Context<Playbook>, playbook: &Playbook) -> Result<()> {
let credentials = ctx.credentials.read().await;

Expand Down

0 comments on commit cb61356

Please sign in to comment.