-
-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check period for given timestamp while checking for uniqueness #927
Comments
This is a legacy decision that I've regretted and wanted to fix for a long time. What do you think about an additional unique field that allows controlling the timestamp it considers? use Oban.Worker, unique: [period: 60, timestamp: :scheduled_at] The default |
Going about it this way limits the solution to handle only one timestamp. Backwards compatibility of the variant I proposed could be achieved in a following way – period's type is Btw, I already implemented it that way for the project I was referring to, and there is another detail – |
The goal is only to handle one timestamp. The logic around unique checks is complex enough; extending it to check multiple timestamps would make it even more opaque. It's always possible to support custom unique checks with multiple timestamps in your own application if necessary. However, that isn't a direction I'm willing to go for the core
Why use |
Ah ok. Then I'll rewrite it to handle only one.
IMO it'll be nice to be able to define it in the worker itself, however there might be possible mix up of storage- and logic-level code.
Indeed, seems I missed that option. The only reason left is for clarity. |
Shouldn't uniqueness check be performed relative to the field rather than now? PS Just switched from my fork to |
The only change in that function was to dynamically select the field to check (either - defp since_period(query, period) do
- where(query, [j], j.inserted_at >= ^seconds_from_now(-period))
+ defp since_period(query, period, timestamp) do
+ where(query, [j], field(j, ^timestamp) >= ^seconds_from_now(-period)) |
Is your feature request related to a problem? Please describe.
We use Oban to make our entities transition from one state to another in background.
Such Jobs can be scheduled system-wide or per entity, but in both cases we would like to rely on oban unique feature to ensure that our system is not scheduling the same job twice and that we're not overloading our system with too many jobs.
To allow for that to happen we initially though that we can just configure
period
.But upon closer inspection we found out that period is checked in relation to the job's
inserted_at
timestamp, which is not what we want.Describe the Solution You'd Like
Either of the following would work for us, but IMO the second option adds more flexibility:
Allow for period to be checked in relation to the job's
scheduled_at
timestamp, e.g.:Allow for dynamic options definition, e.g.:
Describe Alternatives You've Considered
It is possible to achieve described above behaviour by disabling Oban's uniqueness check and implementing it in the application code, but it would be nice to have it out of the box.
The text was updated successfully, but these errors were encountered: