**Carabao Dev Log**
After so much work, I finally converted the `sqlx` postgres adapter of `apalis` to `diesel` where untyped queries are only annoying if you don't have for it and the lack of support for async database triggers. I also had to dig deep and learn `tower` just to get it to compile.
All this for a background job processor. Much to clean up as well as determine the testing strategy.
I AM DEFINITELY STILL OKAY
**Carabao Dev Log**
I am heavily reworking and refactoring my database test creation with a builder pattern that feels pragmatic enough. Might have to make the skeleton into a macro again.
Anyway, I just found marking functions and structs `#[deprecated]` while refactoring to easily mark things I needed to change since `cargo clippy` issues a compilation warning. Not a novel approach I guess but just surprised I was able to use it.
Docs: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
Toro rosso, questa non è un’esercitazione! Portate qui le bibite. E le ali?
https://www.jacoporanieri.com/blog/?p=38075
#creature #animali #tori #mucche #bufali #dal mondo #malesia #vietnam #filippine #colori #rosso #anomalie #genetica #varianti #strano #internet #meme #viral #asia #carabao #bovini #artiodattili #allevamento
#creature #animali #tori #mucche #bufali #dal #malesia #vietnam #filippine #colori #rosso #anomalie #genetica #varianti #strano #internet #meme #viral #asia #carabao #bovini #artiodattili #allevamento
**Carabao Dev Log**
Good news, I learned that marking `actix::Actor` as `actix::SystemService` makes it much more convenient for my setup and with the tests. It is just strange it is not in the main documentation.
Bad news, I was wrong about the global database connection and had to create a flag/guard for a per-thread test pool (of 1) so that the tests are consistent. The things I do for a test harness.
`actix::registry::SysemRegistry `: https://docs.rs/actix/latest/actix/registry/struct.SystemRegistry.html
**Carabao Dev Log**
Just found out that `cargo fmt` can be used to format `Cargo.toml` files but the PR for it is not yet merged. Not sure I agree with the actual formatting, but I do want more a standard method and tool.
Github Comment: https://github.com/rust-lang/rustfmt/pull/5240#issuecomment-1519977712
**Carabao Dev Log**
So creating an event bus with `actix` did involve some `macro_rules`. The type safety though of handlers is fascinating where each message must have a handler instead of letting it silently ignored.
On the testing side, I am surprised that testing database connections across multiple actors with their own pools still produce a consistent test result somehow as if they use a global test connection. 🤷
**Carabao Dev Log**
I wish there was an quick event bus solution for `actix` where I am writing so many `impl Handler` to broadcast messages. If anybody wants to make that where you can just maybe register an `Actor` then just write the `Handler`s would be great. Yet I do think it might not be possible without some `macro` magic which would also be a dealbreaker.
Although this makes me reflect the things I neglected while working with /Elixir/ and its global registry.
**Carabao Dev Log**
Writing tests for the OAuth entities now since I feel it is stable now. My current problem is now running a `diesel` transaction within a transaction since test connections use a test transaction via `conn.begin_test_transaction()`. Thankfully this is easy to resolve:
```
conn.begin_test_transaction();
/// DOES NOT WORK
/// conn.build_transaction().run(...);
/// WORKS
conn.transaction(...);
```
**Carabao Dev Log**
Still fixing up my PR for adding a missing OAuth `client_credentials` but for now I came across this footgun with filtering `NULL` database fields with `diesel`. Instead of `field.eq(None)`, it was actually `field.is_null()` which kinda feels a little bad on the Rust side, but makes sense in SQL. (The fragment `table.field = NULL` is not the same as `table.field IS NULL`.)
**Carabao Dev Log**
I am so blind for not noticing there were async bindings for the critical traits in `oxide_auth` named `oxide_auth_async`. Would have saved me time from finding ways to run async functions inside non-async functions. Still have to integrate it a bit later though.
Github Issue: https://github.com/HeroicKatora/oxide-auth/issues/76#issuecomment-864237929
`oxide_auth_actix`: https://docs.rs/oxide-auth-actix/latest/oxide_auth_actix/
**Carabao Dev Log**
Refactoring my database operation to have an macro generated async version from a sync version instead of just all async really helped although I still question if this is healthy.
```
#[with_async]
pub fn get_by_id(conn: &mut PgConnection, id: &Uuid) -> AnyhowResult<Entity> { ... }
/// Generates a $name_ident async version
pub async fn get_by_id_async(...)
```
**Carabao Dev Log**
At last, I was able to integrate the OAuth2 library(`oxide_auth`) for my `actix-web` project. So many days and so much code to finally just get an access bearer token. 🥳 😭
Still have some more work and cleanup to do but I do wonder if there is an easier OAuth2 server library integration.
`oxide_auth`: https://github.com/HeroicKatora/oxide-auth
**Carabao Dev Log**
Revelation, I was trying to make my error wrapping better. In particular, I was trying to convert a missing database entry error into an application specific error and doing `convert(action.await?)` feels lacking.
So I tried doing a simple `Extension Traits` for `anyhow` errors and it just feels good doing `action.await.not_found("app_id")?`.
Extension Trait: http://xion.io/post/code/rust-extension-traits.html
Anyhow Error: https://docs.rs/anyhow/latest/anyhow/struct.Error.html
**Carabao Dev Log**
Almost close to finishing my initial crating refactoring. I came across this strange macro issue:
`type `fn(String) -> Wrapper {Wrapper}` is private
private type`
The issue is that I forgot to add `pub` to the inner wrapper type but the error was hard to understand behind a macro error.
The debugging tactic I used is to copy the output of `cargo expand` and get a better compiler error which took me longer to realize.
**Carabao Dev Log**
So I refactored my models to use the new typed de/serialization strategy and it feels good keeping the `diesel` dependency in one subcrate.
Sadly for ad-hoc query types like returning a few fields, I have to use the new wrapper types then convert them to its intended type which is a minor inconvenience.
The last gotcha is manually implementing `Nullable` since it is not automatically derived for custom types which is hard to detect.
Still a win
**Carabao Dev Log**
OMG, `diesel` has `deserialize_as` and `serialize_as` which helps me in writing less macros and implementing less types. I need to rethink my approach here.
Insertable: https://docs.diesel.rs/master/diesel/prelude/derive.Insertable.html#optional-field-attributes
Queryable: https://docs.diesel.rs/master/diesel/deserialize/derive.Queryable.html#optional-field-attributes
**Carabao Dev Log**
So I am in the process of splitting my project into multiple crates and it is somewhat relaxing and cathartic. Sadly, I am running into safe type conversions that are hard to refactor. I may have to bite the bullet to allow `unsafe` just for type conversions.
**Carabao Dev Log**
At last, the OAuth2 intergration of `oxide-oauth` is working with `code` response type. I have been trying to figure out how it works and took so long. 😭 Just so happy it works but I have to add some protections like CSRF and so on.
**Carabao Dev Log**
So I finally figured out why rendering an HTML body with `Yew SSR` then passing it to an `Askama template` never renders properly. It was because the `Askama` by default HTML escapes by default and I just had to disable that. 😅
```rust
#[derive(Template)]
#[template(path = "page.html", escape = "none")]
pub struct PageTemplate<'a> { }
```
**Carabao Dev Log**
Cleaning up some test code and I realized that pool connections were not started in a transaction. If I did try to start a transaction, I get a transaction in a transaction error.
With `r2d2`, a pool can be configured to do this on connection checkout which is neat.
Snippet: https://pastebin.com/jLtuPKYP
r2d2: https://docs.rs/r2d2/latest/r2d2/trait.CustomizeConnection.html