{"id":23339041,"url":"https://github.com/geofmureithi-zz/apalis","last_synced_at":"2025-04-09T22:32:27.528Z","repository":{"id":45487294,"uuid":"257936927","full_name":"geofmureithi-zz/apalis","owner":"geofmureithi-zz","description":"Efficient and reliable background processing for Rust using Actix and Redis","archived":false,"fork":false,"pushed_at":"2021-12-11T03:50:15.000Z","size":104,"stargazers_count":17,"open_issues_count":5,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T04:36:13.531Z","etag":null,"topics":["actix","background-processing","jobs","queue","redis-queue","scheduling"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/geofmureithi-zz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-22T15:09:11.000Z","updated_at":"2024-05-10T23:28:29.000Z","dependencies_parsed_at":"2022-07-18T22:18:33.923Z","dependency_job_id":null,"html_url":"https://github.com/geofmureithi-zz/apalis","commit_stats":null,"previous_names":["geofmureithi/actix-jobs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geofmureithi-zz%2Fapalis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geofmureithi-zz%2Fapalis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geofmureithi-zz%2Fapalis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geofmureithi-zz%2Fapalis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geofmureithi-zz","download_url":"https://codeload.github.com/geofmureithi-zz/apalis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248123778,"owners_count":21051532,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actix","background-processing","jobs","queue","redis-queue","scheduling"],"created_at":"2024-12-21T03:17:31.480Z","updated_at":"2025-04-09T22:32:27.504Z","avatar_url":"https://github.com/geofmureithi-zz.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Apalis [![Build Status](https://travis-ci.org/geofmureithi/apalis.svg?branch=master)](https://travis-ci.org/geofmureithi/apalis)\n\nSimple and reliable background processing for Rust using Actix actors. Apalis currently supports Redis as a store, with SQlite, PostgresSQL and MySQL in the pipeline.\n\n## Getting Started\n\nTo get started, just add to Cargo.toml\n\n```toml\n[dependencies]\napalis = { version = \"0.2\", features = [\"redis\"] }\n```\n\n### Prerequisites\n\nA running redis server is required.\nYou can quickly use docker:\n\n```bash\ndocker run --name some-redis -d redis\n```\n\n## Usage\n\n```rust\nuse actix::prelude::*;\nuse apalis::{\n    redis::{RedisConsumer, RedisProducer, RedisStorage}\n    Job, JobContext, JobFuture, JobHandler, Queue, Worker\n};\nuse serde::{Deserialize, Serialize};\nuse std::sync::Arc;\nuse std::sync::Mutex;\n\n#[derive(Debug)]\npub enum MathError {\n    InternalError,\n}\n\n#[derive(Serialize, Deserialize)]\npub enum Math {\n    Add(u64, u64),\n    Fibonacci(u64),\n}\n\nimpl Job for Math {\n    type Result = Result\u003cu64, MathError\u003e;\n}\n\nimpl JobHandler\u003cRedisConsumer\u003cMath\u003e\u003e for Math {\n    type Result = JobFuture\u003cResult\u003cu64, MathError\u003e\u003e;\n    fn handle(\n        self,\n        ctx: \u0026mut JobContext\u003cRedisConsumer\u003cMath\u003e\u003e,\n    ) -\u003e JobFuture\u003cResult\u003cu64, MathError\u003e\u003e {\n        let data = ctx.data_opt::\u003cArc\u003cMutex\u003cMathCounter\u003e\u003e\u003e().unwrap();\n        let mut data = data.lock().unwrap();\n        data.counter += 1;\n        match self {\n            Math::Add(first, second) =\u003e Box::pin(async move { Ok(first + second) }),\n            Math::Fibonacci(num) =\u003e {\n                let addr = ctx.data_opt::\u003cAddr\u003cFibonacciActor\u003e\u003e().unwrap().clone();\n                Box::pin(async move {\n                    addr.send(Fibonacci(num))\n                        .await\n                        .map_err(|_e| MathError::InternalError)?\n                })\n            }\n        }\n    }\n}\n\nfn produce_jobs(queue: \u0026Queue\u003cMath, RedisStorage\u003e) {\n    let producer = RedisProducer::start(queue);\n    producer.do_send(Math::Add(1, 2).into());\n    producer.do_send(Math::Fibonacci(9).into());\n}\n\n#[actix_rt::main]\nasync fn main() {\n    std::env::set_var(\"RUST_LOG\", \"info\");\n    env_logger::init();\n    let storage = RedisStorage::new(\"redis://127.0.0.1/\").unwrap();\n    let queue = Queue::\u003cMath, RedisStorage\u003e::new(\u0026storage);\n\n    //This can be in another part of the program\n    produce_jobs(\u0026queue);\n\n    let counter = Arc::new(Mutex::new(MathCounter { counter: 0 }));\n    let addr = SyncArbiter::start(2, || FibonacciActor); //Get the address of another actor\n    Worker::new()\n        .register_with_threads(2, move || {\n            RedisConsumer::new(\u0026queue)\n                .data(counter.clone())\n                .data(addr.clone())\n        })\n        .run()\n        .await;\n}\n```\n\n## Built On\n\n- [actix](https://actix.rs) - Actor framework for Rust\n- [redis-rs](https://github.com/mitsuhiko/redis-rs) - Redis library for rust\n- [sqlx](https://github.com/launchbadge/sqlx) - The Rust SQL Toolkit\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/geofmureithi/apalis/tags).\n\n## Authors\n\n- **Njuguna Mureithi** - _Initial work_ - [Njuguna Mureithi](https://github.com/geofmureithi)\n\nSee also the list of [contributors](https://github.com/geofmureithi/apalis/contributors) who participated in this project.\n\nIt was formally `actix-redis-jobs` and if you want to use the crate name please contact me.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n\n## Acknowledgments\n\n- Inspiration: The redis part of this project is heavily inspired by [Curlyq](https://github.com/mcmathja/curlyq) which is written in GoLang\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeofmureithi-zz%2Fapalis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeofmureithi-zz%2Fapalis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeofmureithi-zz%2Fapalis/lists"}