Current section
Files
Jump to
Current section
Files
README.md
# M25[](https://hex.pm/packages/m25)[](https://hexdocs.pm/m25/)A background job queueing and scheduling library for Gleam!## Getting StartedInstall M25:```shgleam add m25```Create a `pog` connection. You should generally start both `pog` and `m25` in asupervised manner.```gleamimport m25pub fn main() -> Nil { let conn_name = process.new_name("db_connection") let conn_child = pog.default_config(conn_name) |> pog.host("localhost") |> pog.database("my_database") |> pog.pool_size(15) |> pog.supervised // Create a connection that can be accessed by our queue handlers let conn = pog.named_connection(conn_name) let assert Ok(m25) = m25.new(conn) |> m25.add_queue(email_queue()) |> result.try(m25.add_queue(_, sms_queue())) let m25_child = m25.supervised(m25, 1000) let assert Ok(started) = static_supervisor.new(static_supervisor.OneForOne) |> static_supervisor.add(conn_child) |> static_supervisor.add(m25_child) |> static_supervisor.start // Your queues will now be set up and jobs will start executing // in the background!}```You can then enqueue jobs using the [`m25.enqueue`](https://hexdocs.pm/m25/m25.html#enqueue)function.```gleamlet job = m25.new_job(job_input) |> m25.schedule(at: future_time) |> m25.retry(max_attempts: 3, delay: option.Some(duration.seconds(3)))let assert Ok(_) = m25.enqueue(conn, my_queue, job)```Further documentation can be found at <https://hexdocs.pm/m25>. You will also find arunnable example in [`dev/m25_dev.gleam`](./dev/m25_dev.gleam). This will run againstthe Postgres database configured in the [`compose.yml`](./compose.yml) file.## Delivery SemanticsM25 aims to deliver jobs at least once. If a job fails, either by returning an error,crashing, timing out, or failing to respond to heartbeats, M25 will mark the job asfailed and retry according to the configured retry policy.Jobs that are stuck in an executing state will be cleaned up after a configurabletimeout, and can be retried.## TablesThis driver creates tables in the `m25` schema to store jobs.The current tables created by this driver are:| Table Name | Description || ---------- | ----------------------------------------------------------------------- || `job` | Stores jobs, both executing and executed. || `version` | Stores the latest version of the M25 migrations that have been applied. |## MigrationsYou can run migrations against yourdatabase using the provided CLI:```shgleam run -m m25 migrate --addr=<connection_string>```The required SQL statements will be printed to the console for use with other migrationtools like [`dbmate`](https://github.com/amacneil/dbmate). Alternatively, you canapply the migrations directly using the `--apply` flag.Support for [Cigogne](https://github.com/Billuc/cigogne) is in the works.## Development```shdocker compose up -d # Start the local Postgres instancegleam dev # Run the examplegleam test # Run the tests```## Why 'M25'?This is the M25.