Sequences Next Number Cron job


(Fares Younis) #1

Hello community.


My idea to reset this number on daily bases, maybe by using tryton cron jobs or using pgsql cron jobs.

What do you think is the best? and is there any reference for the usage of tryton cron jobs?


(Cédric Krier) #2

I do not think it is possible to guarantee that the cron job will reset the sequence exactly at the right time, so you may have a number generated with the old next number.
But why resetting the sequence?
Otherwise, you could use something else than a sequence like counting the number of record for the date and increase by one (but requires to lock the table to avoid concurrency).


(Fares Younis) #3

I have done it using Postgresql cron job, that is reseting the sequence next number everyday.
And to avoid concurrency I added the year month day then the sequence number which is resting at the end of each day.


(Cédric Krier) #4

For me, a cron job can not guarantee that the sequence will be reset at the right time prior to any usage for the day. Maybe for your case, it is not a problem, but then why resetting the sequence?


(Fares Younis) #5

For sure it depends on the use case, in my case there will be no demand on the targeted sequence, this is the only solution that I can do so far, the idea is very similar to queue number issuing, every day the queue must begin from number 1.


(Cédric Krier) #6

But your solution does not guarantee that. You can not enforce that the cron will be run at the right time.
If you really want to make a queue numbering, you must go with the solution: