Skip to content

Commit

Permalink
refactor!: simplify code (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxartio authored Feb 13, 2025
1 parent 5aa9910 commit 7425d71
Show file tree
Hide file tree
Showing 39 changed files with 352 additions and 1,189 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/book.yml

This file was deleted.

29 changes: 3 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,12 @@ all-features = true

[features]
default = []
redis = ["dep:redis"]
json = ["dep:serde", "dep:serde_json"]
tokio = ["dep:tokio"]

[dependencies]
async-trait = "0.1"
redis = { version = "0.28", features=["connection-manager", "tokio-comp"], optional = true }
serde = { version = "1.0", features = ["serde_derive"], optional = true }
serde_json = { version = "1.0", optional = true }
tokio = { version = "1.43", features = ["time"], optional = true }
redis = { version = "0.28", features=["connection-manager", "tokio-comp"]}

[dev-dependencies]
tokio = { version = "1.43", features = ["time", "macros", "rt-multi-thread"]}
redis = { version = "0.28", features=["connection-manager", "tokio-comp"] }
serde = { version = "1.0", features = ["serde_derive"] }
serde_json = { version = "1.0" }

[[example]]
name = "memory"
required-features = ["tokio"]

[[example]]
name = "redis"
required-features = ["redis", "tokio"]

[[example]]
name = "redis_json"
required-features = ["redis", "json", "tokio"]

[[example]]
name = "redis_json_autodelete"
required-features = ["redis", "json", "tokio"]
tokio = { version = "1.43", features = ["time", "macros", "rt-multi-thread"]}
tokio-util = { version = "0.7.13", features = ["full"] }
11 changes: 11 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
all: fmt check test

check:
cargo fmt --all -- --check
cargo clippy --all-features --all-targets -- -D warnings

test:
cargo test --all-features

fmt:
cargo fmt --all
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2022 Danil Akhtarov <[email protected]>
Copyright (c) 2025 Danil Akhtarov <[email protected]>

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
25 changes: 0 additions & 25 deletions Makefile

This file was deleted.

39 changes: 24 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,24 @@
[![Docs.rs](https://docs.rs/taskline/badge.svg)](https://docs.rs/taskline)
<!-- [![Coverage Status](https://coveralls.io/repos/github/daxartio/taskline/badge.svg?branch=main)](https://coveralls.io/github/daxartio/taskline?branch=main) -->

The library allows for creating scheduled tasks via Redis for Rust.
Taskline is a Rust library for scheduling tasks via Redis.

```rust
producer.schedule(&"Hello!".to_string(), &(now() + 30000.)).await;
## Overview

loop {
let tasks = consumer.poll(&now()).await.unwrap();
Taskline provides a simple way to schedule and process tasks asynchronously. It follows a producer-consumer model, where a producer schedules tasks to be executed at a specific time, and a consumer retrieves and processes them.

for task in tasks {
println!("Consumed {:?}", task);
}
}
```

That means the Consumed will be printed in 30 seconds.
## Use Cases

You can customize a format of an event for redis. Write your wrapper over [RedisBackend](src/backends/redis.rs). See [redis_json backend](src/backends/redis_json.rs).
Taskline is ideal for applications that require deferred execution, such as:

![diagram](diagram.png)
- Scheduling emails to be sent at a later time.
- Sending notifications to users at a specific moment.
- Any background job that needs time-based execution.

## Features

- [x] Send/receive tasks in Redis
- [x] Delayed tasks
- [x] Support json
- [x] Deleting from a storage after handling
- [ ] Support Redis Cluster
- [ ] Metrics
Expand All @@ -46,6 +39,22 @@ You can customize a format of an event for redis. Write your wrapper over [Redis
cargo add taskline
```

## Task Auto-Deletion

### Default Behavior

By default, Taskline automatically deletes tasks from storage after they are processed. This is the recommended approach for most use cases, as it ensures tasks are not executed multiple read.

### Disabling Auto-Deletion

If you prefer to manually manage task deletion, you can disable auto-delete by setting `autodelete=false`. However, this should only be used with a single consumer to avoid duplicate processing. If multiple consumers are involved, consider using a distributed lock mechanism like [redlock](https://redis.com/glossary/redlock/). For more details, see [Distributed Locks with Redis](https://redis.io/docs/manual/patterns/distributed-locks/).

To manually remove a processed task, use: `Taskline::delete`.

### Recommendation

If your use case allows, it is recommended to keep `autodelete=true`, as it simplifies task management and reduces configuration overhead. However, be aware that in the event of an application crash, tasks may be lost before they are processed.

## License

* [MIT LICENSE](LICENSE)
Expand Down
10 changes: 0 additions & 10 deletions book.toml

This file was deleted.

48 changes: 0 additions & 48 deletions diagram.d2

This file was deleted.

Binary file removed diagram.png
Binary file not shown.
14 changes: 0 additions & 14 deletions docs/SUMMARY.md

This file was deleted.

14 changes: 0 additions & 14 deletions docs/additional-resources.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/changelog.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/code-of-conduct.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/contributing.md

This file was deleted.

18 changes: 0 additions & 18 deletions docs/introduction.md

This file was deleted.

33 changes: 0 additions & 33 deletions docs/quick-start.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/user-guide/README.md

This file was deleted.

20 changes: 0 additions & 20 deletions docs/user-guide/autodelete.md

This file was deleted.

16 changes: 0 additions & 16 deletions docs/user-guide/format.md

This file was deleted.

Loading

0 comments on commit 7425d71

Please sign in to comment.