Expand description
Actions for Laravel Rust: encapsulate business logic in structs that run now or on the queue.
An action is a struct with a handle method. Run it where you are, or hand it to the queue
with the same call shape:
ⓘ
use laractions::{Action, action};
#[derive(Default, Serialize, Deserialize)]
pub struct SendEmail {}
#[action(tries = 3, queue = "emails")]
impl SendEmail {
async fn handle(&self, email: String, subject: String, message: String) -> laravel::Result<()> {
Ok(())
}
}
SendEmail::create().run(("user@example.com", "Welcome!", "Hello User")).await?;
SendEmail::create()
.queue("high")
.delay(10)
.retry(5)
.dispatch(args! { email: "user@example.com", subject: "Welcome!", message: "Hello User" })
.await?;It is the port of the PHP package edulazaro/laractions
to Laravel Rust 0.1 (beta), and its API follows the framework’s changes until 1.0.
Re-exports§
pub use action::Action;pub use action::Pending;pub use action::Reference;pub use action::Settings;pub use arguments::Arguments;pub use arguments::IntoArguments;pub use arguments::Parameter;pub use arguments::Resolved;pub use concerns::Actions;pub use concerns::HasActions;pub use concerns::IsActor;pub use concerns::NamedAction;pub use error::ActionError;pub use job::ActionJob;pub use job::MAX_TRIES;pub use provider::LaractionsServiceProvider;pub use registry::Registration;pub use trace::ActionTrace;
Modules§
Macros§
- actions
- Build the
Actionsof a model:actions! { "send_email" => SendEmail }. - args
- Build named arguments, the closest Rust has to
run(email: 'a', subject: 'b').
Attribute Macros§
- action
- Turn the
handlemethod of an impl into an action.