Skip to content

Commit

Permalink
v0.4.0 (#7)
Browse files Browse the repository at this point in the history
* move seat processing to bg

* background create + sit

* cargo updates + table cleanup

* release prepare - v0.4.0

* set roller appropriately
  • Loading branch information
dadleyy authored Jan 15, 2022
1 parent dcfc451 commit 4f9c311
Show file tree
Hide file tree
Showing 18 changed files with 671 additions and 406 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ STICKBOT_ADMIN_EMAILS=""
STICKBOT_MAX_ACTIVE_TABLES_PER_PLAYER=

BOXBOT_WORKER_DELAY=1000

STICKBOT_TABLE_COLLECTION="stickbot:tables"
STICKBOT_TABLE_LIST_COLLECTION="stickbot:table_list"
STICKBOT_PLAYER_COLECTION="stickbot:players"
STICKBOT_JOB_QUEUE="stickbot:jobs"
STICKBOT_JOB_RESULTS="stickbot:job_results"
50 changes: 25 additions & 25 deletions Cargo.lock

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

20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2022 Danny Hadley

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2 changes: 1 addition & 1 deletion workspace/bankah/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bankah"
version = "0.3.4"
version = "0.4.0"
edition = "2018"

[dependencies]
Expand Down
61 changes: 61 additions & 0 deletions workspace/bankah/src/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::state::BetState;
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "snake_case")]
pub struct BetJob {
pub bet: BetState,
pub player: uuid::Uuid,
Expand All @@ -10,18 +11,28 @@ pub struct BetJob {
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "snake_case")]
pub struct RollJob {
pub table: uuid::Uuid,
pub version: uuid::Uuid,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "snake_case")]
pub struct JobWapper<T> {
pub job: T,
pub id: uuid::Uuid,
pub attempts: u8,
}

impl<T> JobWapper<T> {
pub fn wrap(job: T) -> Self {
let id = uuid::Uuid::new_v4();
let attempts = 0u8;
Self { job, attempts, id }
}
}

impl<T> JobWapper<T> {
pub fn retry(self) -> Self {
let JobWapper { job, id, attempts } = self;
Expand All @@ -34,15 +45,20 @@ impl<T> JobWapper<T> {
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "snake_case")]
pub enum TableAdminJob {
ReindexPopulations,
CleanupPlayerData(String),
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "snake_case")]
pub enum TableJob {
Bet(JobWapper<BetJob>),
Roll(JobWapper<RollJob>),
Sit(JobWapper<(String, String)>),
Create(JobWapper<String>),
Stand(JobWapper<(String, String)>),
Admin(JobWapper<TableAdminJob>),
}

Expand All @@ -51,10 +67,21 @@ impl TableJob {
match self {
TableJob::Bet(inner) => inner.id.clone(),
TableJob::Roll(inner) => inner.id.clone(),
TableJob::Sit(inner) => inner.id.clone(),
TableJob::Create(inner) => inner.id.clone(),
TableJob::Stand(inner) => inner.id.clone(),
TableJob::Admin(inner) => inner.id.clone(),
}
}

pub fn sit(table: String, player: String) -> Self {
TableJob::Sit(JobWapper::wrap((table, player)))
}

pub fn stand(table: String, player: String) -> Self {
TableJob::Stand(JobWapper::wrap((table, player)))
}

pub fn admin(job: TableAdminJob) -> Self {
let id = uuid::Uuid::new_v4();
TableJob::Admin(JobWapper { job, id, attempts: 0 })
Expand Down Expand Up @@ -95,6 +122,7 @@ impl TableJob {
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum BetFailureReason {
InsufficientFunds,
InvalidComeBet,
Expand All @@ -104,16 +132,49 @@ pub enum BetFailureReason {
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TableJobOutput {
BetProcessed,
BetStale,
BetFailed(BetFailureReason),
RollProcessed,
RollStale,
AdminOk,
StandOk,
FinalStandOk,
SitOk,
TableCreated(String),
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct JobResult<T> {
completed: Option<chrono::DateTime<chrono::Utc>>,
output: Option<T>,
id: uuid::Uuid,
}

impl<T> JobResult<T> {
pub fn empty(id: uuid::Uuid) -> Self {
return Self {
id,
completed: None,
output: None,
};
}

pub fn wrap(id: uuid::Uuid, inner: T) -> Self {
let completed = Some(chrono::Utc::now());
Self {
output: Some(inner),
id,
completed,
}
}
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum JobError {
Retryable,
Terminal(String),
Expand Down
8 changes: 8 additions & 0 deletions workspace/bankah/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
use serde::Serialize;

pub mod jobs;
pub mod state;

#[derive(Debug, Serialize)]
pub struct JobResponse {
pub job: uuid::Uuid,
pub output: Option<jobs::TableJobOutput>,
}
2 changes: 1 addition & 1 deletion workspace/stickbot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stickbot"
version = "0.3.4"
version = "0.4.0"
edition = "2018"

[lib]
Expand Down
5 changes: 5 additions & 0 deletions workspace/stickbot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ with these services.
Once the environment variables have been prepared, the main web process and background worker can be started using the
appropriate `cargo` aliases:

```
$ cargo stickbot <- web thread
$ cargo boxbot <- background worker
```


[rust]: https://www.rust-lang.org/
[twowaiyo]: https://github.com/dadleyy/twowaiyo
Expand Down
Loading

0 comments on commit 4f9c311

Please sign in to comment.