I am developing a Queueable class to send data to an external system via HTTP callouts. I am planning to chain this class to call itself multiple times, until all records have been processed, or until I hit some limit for re-queue to prevent forever running retries. Once all records have been synced (or the re-queue limit has been reached), I will call the next Queueable class in the chain.
My initial thought is that I'd use a
static variable to track the queue depth, but this won't work because
static variables live inside the current transaction only, so I need some way to share state between Queueable executions to track my current queue depth.
One thing I thought of was to persist this value to the database, but I don't like it because there could be concurrency issues if jobs were to overlap for some reason.
Has anyone else solved this problem, and if so how?