[英]How to Reschedule the Schedule Script in Netsuite using SuiteScript 2.0 version
I want to reschedule the schedule script , when the schedule script usage before hitting the governor limits.我想重新安排调度脚本,当调度脚本使用达到调控器限制之前。 schedule script in Netsuite has 10,000 units. Netsuite 中的调度脚本有 10,000 个单元。 In SuiteScript 1.0 version, rescheduling is acheived by "nlapiScheduleScript() api " but in SuiteScript 2.0 version how to reschedule the script.在 SuiteScript 1.0 版本中,重新调度是通过“nlapiScheduleScript() api”实现的,但在 SuiteScript 2.0 版本中如何重新调度脚本。
help me to achieve this,thanks in advance.帮助我实现这一目标,提前致谢。
The N/task
and N/runtime
modules have what you're looking for. N/task
和N/runtime
模块有你要找的东西。 You'll use N/task
to do the rescheduling, and N/runtime
to get the current script info.您将使用N/task
进行重新调度,并使用N/runtime
获取当前脚本信息。
Without your exact code I can't give a very specific example, but your scheduled script will end up looking generally something like:如果没有您的确切代码,我无法给出一个非常具体的示例,但是您的预定脚本最终看起来通常类似于:
/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
*/
define(['N/task', 'N/runtime'], function(task, runtime) {
/**
* Reschedules the current script and returns the ID of the reschedule task
*/
function rescheduleCurrentScript() {
var scheduledScriptTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT
});
scheduledScriptTask.scriptId = runtime.getCurrentScript().id;
scheduledScriptTask.deploymentId = runtime.getCurrentScript().deploymentId;
return scheduledScriptTask.submit();
}
function execute(context) {
// Do stuff...
while(...) {
// Do processing in loop
// Check remaining usage and reschedule if necessary
if (runtime.getCurrentScript().getRemainingUsage() < 100) {
var taskId = rescheduleCurrentScript();
log.audit("Rescheduling status: " + task.checkStatus(taskId));
return;
}
}
}
return {
execute: execute
};
});
It seems like scheduledScriptTask.submit() is returning null.似乎 scheduleScriptTask.submit() 返回 null。
var taskId = rescheduleCurrentScript();
taskId above returns null when logged.上面的 taskId 在记录时返回 null。 Is it possibly a bug in NetSuite side?它可能是 NetSuite 方面的错误吗?
The accepted answer is good for occasional yields.接受的答案有利于偶尔的收益。 In addition to this if you know you are going to often breach the governance limits you may want to consider a Map/Reduce script instead as it has yielding/resuming built in.除此之外,如果您知道自己会经常违反治理限制,您可能需要考虑使用Map/Reduce 脚本,因为它内置了 yielding/resuming。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.