N/task
및 N/runtime
모듈에 원하는 모듈이 있습니다. 다시 스케줄을 수행하려면 N/task
을 사용하고 현재 스크립트 정보를 얻으려면 N/runtime
을 사용합니다. 정확한 코드없이
나는 매우 구체적인 예를 들어 줄 수는 없지만, 예약 된 스크립트는 일반적으로 같은 것을 찾고 끝날 것입니다 : 그것은 scheduledScriptTask.submit처럼 보인다
/**
* @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
};
});
이렇게하면 실행중인 동일한 지점에서 스크립트를 종료 할 수 있습니까? 예를 들어 예약 된 스크립트에서 저장된 검색의 결과를 반복 할 때이 방법을 사용하면 스크립트가 중단 된 저장된 검색에서 동일한 결과로 예약 된 스크립트가 다시 시작될 수 있습니까? 아니면 저장된 검색의 첫 번째 결과에서 시작할 것입니까? –
예약 된 스크립트를 다시 예약 할 때마다 중단 된 위치에서 다시 시작하는 작업을 관리해야합니다. 일반적으로 내부 ID로 결과를 정렬하고 마지막으로 처리 된 ID를 저장하며 마지막으로 처리 된 ID보다 큰 내부 ID를 검색하여 필터링합니다. – erictgrubaugh
마지막 처리 ID를 저장하는 가장 안전한 장소는 어디입니까? –