apalis
apalis copied to clipboard
Adding `RateLimitLayer` results in a compilation error
I am not sure why the error happens, but as soon as I remove the RateLimitLayer
, the error disappears.
Here is what the code looks like:
.register_with_count(3, {
WorkerBuilder::new("perform_application_job")
.layer(ApalisRateLimitLayer::new(
rate_limit_num,
Duration::new(5, 0),
))
.layer(ApalisTraceLayer::new())
.data(importer_service_1.clone())
.data(exporter_service_1.clone())
.data(media_service_4.clone())
.data(exercise_service_1.clone())
.with_storage(perform_application_job_storage.clone())
.build_fn(perform_application_job)
})
Tried changing the order of layers, count from 3 -> 1. Did not work.
https://github.com/IgnisDa/ryot/blob/b9019dfa1f5948c071857a076ac7e14146d592d8/apps/backend/src/main.rs#L310-L322 are the lines if you are interested.
Could you try to check clone and check service clone? https://docs.rs/tower/latest/tower/builder/struct.ServiceBuilder.html#method.check_clone
You can access the service builder using WorkerBuilder.chain
@geofmureithi I am not sure what I need to do with the methods you gave. I added them to my code, it didn't change the error.
Have you checked this issue? https://github.com/geofmureithi/apalis/discussions/256
See also https://github.com/tokio-rs/axum/discussions/987#discussioncomment-2678595
The issue is that from 0.5 apalis needs the service to be clone yet tower rate limit is not clone.
The suggested option is to include BufferLayer infront of the rate limit one.
The suggested option is to include BufferLayer infront of the rate limit one.
I did that, still does not work. The error has changed:
Seems the issue here is with tower.
Can you try using .chain
Can you also try using a custom implementation eg https://medium.com/@khalludi123/creating-a-rate-limiter-middleware-using-tower-for-axum-rust-be1d65fbeca
Got it working with:
.register_with_count(
1,
WorkerBuilder::new("perform_application_job")
.data(importer_service_1.clone())
.data(exporter_service_1.clone())
.data(media_service_4.clone())
.data(exercise_service_1.clone())
.with_storage(perform_application_job_storage.clone())
.chain(|s| {
s.layer(BufferLayer::new(1024))
.layer(ApalisRateLimitLayer::new(
rate_limit_num,
Duration::new(5, 0),
))
.layer(ApalisTraceLayer::new())
})
.build_fn(perform_application_job),
)
Should I keep this issue open? (Since I had to use a workaround).
I will check the problem then close it.
Cool! Thanks for your guidance.
@geofmureithi Any updates on this?
@geofmureithi Sorry for the ping. Were you able to find the problem?
Currently I have the register method able to work without clone. The issue though is when using register_with_count, I am trying to figure something. Will update in upcoming 0.6 releases.
This has been fixed by #348
@geofmureithi Thanks. Can you cut a new release?
There is v0.6.0-rc.1