Hello,
Thank you for your work. :)
I am wondering the following things:
- how could someone retrieve the result of a task?
- how could someone run a callback or call another service with the result of a task?
- how could someone use clients or database pool from within a
run function?
(Feel free to tell me if you would like me to split this into multiple issues.)
E.g. I would like to store the result inside the database or transmit the result to another service (in-memory) without doing an API call to localhost if I am running the workers within an API.
And I don't want to build the client/db pool for every task from environment variables.
async fn run(&self, queue: &mut dyn AsyncQueueable) -> Result<(), FangError>
run signature is Result<(), FangError> thus I could not make my own AsyncWorker<AQueue> or AsyncWorkerPool<AQueue> that would handle the result of a task.
And since a task should be serializable, I cannot provide to it clients (database or otherwise) that I would not want serializable but that I would want to access in the run function.
I am thinking that the only way would be to attempt to access a global reference to a singleton or something alike, e.g.:
async fn run(&self, _queue: &mut dyn AsyncQueueable) -> Result<(), FangError> {
// do stuff
let result = ...;
let pool: Pool<Postgres> = get_global_postgres_pool().expect("Posgres pool is not initialized");
pool.acquire().await?.execute("<INSERT result into table>").await?;
Ok(())
}
Though I am not sure that the compiler would allow me to do so.
- Did I miss something?
- Or do you currently use a workaround to achieve this behavior?
- Or would that kind of feature be out of scope of
fang and you don't need this?
Maybe it is part or could be part of the following discussion #101 ?
I understand that this could/would considerably complicate the implementation, but no harm in asking 😇.
Hello,
Thank you for your work. :)
I am wondering the following things:
runfunction?(Feel free to tell me if you would like me to split this into multiple issues.)
E.g. I would like to store the result inside the database or transmit the result to another service (in-memory) without doing an API call to
localhostif I am running the workers within an API.And I don't want to build the client/db pool for every task from environment variables.
runsignature isResult<(), FangError>thus I could not make my ownAsyncWorker<AQueue>orAsyncWorkerPool<AQueue>that would handle the result of a task.And since a task should be serializable, I cannot provide to it clients (database or otherwise) that I would not want serializable but that I would want to access in the
runfunction.I am thinking that the only way would be to attempt to access a global reference to a singleton or something alike, e.g.:
Though I am not sure that the compiler would allow me to do so.
fangand you don't need this?Maybe it is part or could be part of the following discussion #101 ?
I understand that this could/would considerably complicate the implementation, but no harm in asking 😇.