ScheduleRunScriptUTCv2 doesn't seem to work as expected?
-
In the API docs for
ScheduleRunScriptUTCv2
, the description for thescriptName
parameter says:The name of the script with its absolute path to be run.
https://docs.braincloudservers.com/api/capi/script/schedulerunscriptutcv2
I've tried auto-rescheduling a script with
bridge.getScriptName()
given for thescriptName
, which seemingly gives the correct full path, but when the scheduled job tries to run, it says it can't find the script:Script not found: RefreshWeeklyChallengeCourse
This is a snippet of the code used to schedule the new run job:
/** * @returns {number} The next run date in UTC millis. */ function setNextScheduledRun() { let scriptProxy = bridge.getScriptServiceProxy(); const now = new Date(); const nextRunDate = new Date(Date.UTC( now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 2 )); setToNextDayOfWeek(nextRunDate, data.dayOfWeek); let scriptData = data; let scriptName = String(bridge.getScriptName()); let nextRunMillis = nextRunDate.getTime(); bridge.logInfo(`Next run: ${nextRunDate.toISOString()}`); bridge.logInfo(`Next run millis: ${nextRunMillis}`); if (!data.dryRun) { cancelExcessJobs(scriptProxy, scriptName, nextRunDate); } let scheduleResponse = scriptProxy.scheduleRunScriptUTCv2(scriptName, scriptData, nextRunMillis); if (scheduleResponse.status !== 200) { bridge.logErrorJson("Failed to schedule next script run", scheduleResponse); return 0; } return nextRunMillis; }
When I've manually ran the script via the API Explorer, everything works correctly and a job is scheduled. Only once I've moved the script to the root folder does it find the script and work. While this gets the job done, the issue feels like either a bug in the API or a documentation issue that could use updating.
If I'm misunderstanding something, please feel free to correct me, but I wanted to bring it up in the event that it is indeed a bug. Thank you in advance for your time.
-
Hi - clever use of getScriptName() - maybe too clever!
I'm passing this onto the devs. My guess is that
bridge.getScriptName()
isn't returning the full [or proper] path to the script.We'll check it out and get back to you!
-
HI @william ,
The devs identified an "inconsistency" in the implementation of that bridge call - where, depending upon how a script was invoked, the property being consulted to return the results wasn't always set.
We're preparing a fix to patch in later today.
Thanks for reporting this!
-
-
Hi @william,
We've deployed a patch for this. Can you re-test and let it know if it solved your problem?
Paul.
-
Tested and it works like a charm. Thanks again!
-
Cool - good to hear it. And once again: thanks for reporting it!