-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore/nanocld: wip event based process
- Loading branch information
Showing
21 changed files
with
358 additions
and
112 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
2 changes: 2 additions & 0 deletions
2
bin/nanocld/migrations/2022-01-10-150631_object_process_statuses/down.sql
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,2 @@ | ||
-- This file should undo anything in `up.sql` | ||
DROP TABLE IF EXISTS "object_process_statuses"; |
10 changes: 10 additions & 0 deletions
10
bin/nanocld/migrations/2022-01-10-150631_object_process_statuses/up.sql
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,10 @@ | ||
-- Your SQL goes here | ||
CREATE TABLE IF NOT EXISTS "object_process_statuses" ( | ||
"key" VARCHAR NOT NULL PRIMARY KEY, | ||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
"wanted" VARCHAR NOT NULL, | ||
"prev_wanted" VARCHAR NOT NULL, | ||
"actual" VARCHAR NOT NULL, | ||
"prev_actual" VARCHAR NOT NULL | ||
); |
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
2 changes: 1 addition & 1 deletion
2
bin/nanocld/migrations/2024-01-02-135246_metrics_rename_expire/down.sql
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,2 +1,2 @@ | ||
-- This file should undo anything in `up.sql` | ||
ALTER TABLE IF EXISTS "metrics" RENAME COLUMN IF EXISTS "expires_at" TO "expire_at"; | ||
ALTER TABLE IF EXISTS "metrics" RENAME COLUMN "expires_at" TO "expire_at"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use std::str::FromStr; | ||
|
||
use diesel::prelude::*; | ||
|
||
use crate::schema::object_process_statuses; | ||
|
||
#[derive(Debug, Clone, Identifiable, Insertable, Queryable)] | ||
#[diesel(primary_key(key))] | ||
#[diesel(table_name = object_process_statuses)] | ||
pub struct ObjPsStatusDb { | ||
pub key: String, | ||
pub created_at: chrono::NaiveDateTime, | ||
pub updated_at: chrono::NaiveDateTime, | ||
pub wanted: String, | ||
pub prev_wanted: String, | ||
pub actual: String, | ||
pub prev_actual: String, | ||
} | ||
|
||
#[derive(Clone, Debug, Default, AsChangeset)] | ||
#[diesel(table_name = object_process_statuses)] | ||
pub struct ObjPsStatusUpdate { | ||
pub wanted: Option<String>, | ||
pub prev_wanted: Option<String>, | ||
pub actual: Option<String>, | ||
pub prev_actual: Option<String>, | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
pub enum ObjPsStatusKind { | ||
#[default] | ||
Created, | ||
Started, | ||
Running, | ||
Stopped, | ||
Failed, | ||
Unknown, | ||
} | ||
|
||
impl FromStr for ObjPsStatusKind { | ||
type Err = std::io::Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s { | ||
"created" => Ok(Self::Created), | ||
"started" => Ok(Self::Started), | ||
"running" => Ok(Self::Running), | ||
"stopped" => Ok(Self::Stopped), | ||
"failed" => Ok(Self::Failed), | ||
_ => Ok(Self::Unknown), | ||
} | ||
} | ||
} | ||
|
||
impl ToString for ObjPsStatusKind { | ||
fn to_string(&self) -> String { | ||
match self { | ||
Self::Created => "created", | ||
Self::Started => "started", | ||
Self::Running => "running", | ||
Self::Stopped => "stopped", | ||
Self::Failed => "failed", | ||
Self::Unknown => "unknown", | ||
} | ||
.to_owned() | ||
} | ||
} | ||
|
||
pub struct ObjPsStatusPartial { | ||
pub key: String, | ||
pub wanted: ObjPsStatusKind, | ||
pub prev_wanted: ObjPsStatusKind, | ||
pub actual: ObjPsStatusKind, | ||
pub prev_actual: ObjPsStatusKind, | ||
} | ||
|
||
impl From<ObjPsStatusPartial> for ObjPsStatusDb { | ||
fn from(partial: ObjPsStatusPartial) -> Self { | ||
Self { | ||
key: partial.key, | ||
created_at: chrono::Utc::now().naive_utc(), | ||
updated_at: chrono::Utc::now().naive_utc(), | ||
wanted: partial.wanted.to_string(), | ||
prev_wanted: partial.prev_wanted.to_string(), | ||
actual: partial.actual.to_string(), | ||
prev_actual: partial.prev_actual.to_string(), | ||
} | ||
} | ||
} |
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
Oops, something went wrong.