Skip to content
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

Add support for rescheduleIfNeeded to take a callback function for the parameter object #86

Open
steveklett opened this issue Dec 13, 2023 · 0 comments

Comments

@steveklett
Copy link
Contributor

I've encountered this before and just encountered it again. Pretty typical LazySearch use case in a Scheduled Script where I want the script to reschedule itself. In my case I'm passing along process state via the script parameters to support execution resuming from where it left off. The problem is that this state data is updated after the call to rescheduleIfNeeded.

Here's an example:

let lastTransactionIID = 0

export function _makeRescheduleParam(lastProcessedAgingIID: number): object {
  return {
    custscript_gadd_generation_run_id: _getSettings().generationRunID,
    custscript_gadd_last_proc_item_age_iid: lastProcessedAgingIID
  }
}

Seq(LazySearch.from(NV._getPreviousActiveAgingDetailSearch()))
  .takeWhile(rescheduleIfNeeded(governanceRemains(), NV._makeRescheduleParam(lastTransactionIID)))
  .forEach(result => {
    record.submitFields({
      type: 'customrecord_inventoryagingdetail',
      id: result.id,
      values: {
        isinactive: true
      }
    })
    lastTransactionIID = result.id
  })

If we could pass a function we could have something like this:

// ...

Seq(LazySearch.from(NV._getPreviousActiveAgingDetailSearch()))
  .takeWhile(rescheduleIfNeeded(governanceRemains(), () => NV._makeRescheduleParam(lastTransactionIID)))
  .forEach(result => {
    record.submitFields({
      type: 'customrecord_inventoryagingdetail',
      id: result.id,
      values: {
        isinactive: true
      }
    })
    lastTransactionIID = result.id
// ...

There's probably a more graceful way to accomplish, but I think you get the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant