Fang
Background job processing library for Rust.
Currently, it uses Postgres to store state. But in the future, more backends will be supported.
Installation
- Add this to your Cargo.toml
[]
= "0.2"
= "0.1"
= { = "1.0", = ["derive"] }
- Create
fang_taskstable in the Postgres database. The migration can be found in the migrations directory.
Usage
Defining a job
Every job should implement fang::Runnable trait which is used by fang to execute it.
use Error;
use Runnable;
use ;
As you can see from the example above, the trait implementation has #[typetag::serde] attribute which is used to deserialize the job.
Enqueuing a job
To enqueue a job use Postgres::enqueue_task
use Postgres;
...
enqueue_task.unwrap;
Starting workers
Every worker runs in a separate thread. In case of panic, they are always restarted.
Use WorkerPool to start workers. It accepts two parameters - the number of workers and the prefix for the worker thread name.
use WorkerPool;
new.start;
Potential/future features
- Extendable/new backends
- Workers for specific types of tasks. Currently, each worker execute all types of tasks
- Configurable db records retention. Currently, fang doesn't remove tasks from the db.
- Retries
- Scheduled tasks
Contributing
- Fork it!
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
Author
Ayrat Badykov (@ayrat555)