How to implement a daily job for each user object? #144
-
In my app, I need to run a cleanup job for each user once a day. Preferably splayed across 24hrs to avoid peak loads. Users get added and removed regularly. What I came up with was a pair of workers:
This works pretty well, but requires some contortions to get the river.Client into the
Since the docs all initialize the workers before creating the client, I was wondering if I'm holding this wrong and if anyone has a better idea how to structure this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @DavidS-ovm, as of #88 you can now create a We've run into this issue of workers that want access to the client a few times and while what you've shown above is the main way I know to do it today, I agree with you that it's not ideal. The ugliness is part of what keeps us from wanting to show more examples of this usage in the docs, though clearly it's something we should try to improve. Another idea I came up with to try to improve this is summarized in #87 (comment): essentially we could stick the client into a context key in the context that gets passed to If you wanted to, I think you could experiment with this approach on your own entirely in userspace. The context you provide to |
Beta Was this translation helpful? Give feedback.
Hi @DavidS-ovm, as of #88 you can now create a
Client
with an empty or incompleteWorkers
bundle and continue to useAddWorker
to register additional workers up until the client has been started withStart()
(as you've shown in your example). This was a more recent addition and most of the docs were written prior to this.We've run into this issue of workers that want access to the client a few times and while what you've shown above is the main way I know to do it today, I agree with you that it's not ideal. The ugliness is part of what keeps us from wanting to show more examples of this usage in the docs, though clearly it's something we should try to improve.
Another idea I came up wit…