If I have a scheduled script that I want to execut...
# suitescript
w
If I have a scheduled script that I want to execute on a queue-custom record that is constantly added to. What approach would you take to schedule/reschedule itself? 1. Have one deployment that is scheduled every 15 minutes and no rescheduling at the end of the execution. 2. Have two deployments, one that is scheduled every 15 minutes and one that is not scheduled. The first one starts the second one if the governance runs out or if there are new records to process when the execution is complete. The second one will then resubmit itself until there are no more records to process. I suspect that the next scheduled deployment could potentially start at the same time as the not scheduled one is still running. 3. Have one deployment that is not scheduled and let a UE-script on the queue-record try to ScheduledScriptTask.submit() on create. Then the schedule script could reschedule itself at the end and no other deployments could cause a conflict. 4. The help on MapReduceScriptTask.submit() doesn't state the same limitation on scheduled/not scheduled. Perhaps I should re-factor it into a M/R and only have a scheduled deployment that reschedules itself? • According to the documentation, you can't programmatically start a scheduled script instantly unless the deployment is set to "Not Scheduled". If it is set to "Scheduled", it will just queue it based on the schedule. • I don't want to run the risk of two deployments of the same script executing simultaneously and thereby run the risk of processing the same queue record at the same time.
b
this is a very complicated topic and the answers you will depends on how serious you want your queue to be, and how long you plan on supporting it
the easiest solution is to have one script deployment to do all the processing
it used to be easier in suitescript 1 where you could yield when you ran out of points
if you are using suitescript 2, then you can run out of points, at which point you must reschedule your script, which poses a problem for concurrency since you need 2 scripts
its not a terrible problem to solve since you can make the scheduled script exit early if the second script is in the queue
if you work long enough on the problem, you learn about SuiteScript 2.0 Scheduled Script Handling of Server Restarts
at which point you learn that scripts can fail or restart at any time, which means you need to check if the custom record has already been processed before doing your logic
correctly doing that logic by making a lock on the custom record also makes it more thread safe and allows you to have the scheduled script and the unscheduled script running at the same time
w
I'm basically having a "lock" on the queue record since the first thing I do is to change the status to "Processing" from "To be processed". Maybe that wasn't what you meant?
b
depends on how serious the lock implementation is
you need logic to handle unlocking records that fail before unlocking
w
True, I don't think that is implemented. But not that big of deal in this case either.
b
by the time you have a serious queue implantation, you wont fear a queue record being processed at the same time
you will fear the server restarting in the middle
👻 1