I schedule a script with the scheduler, give the time, params and id.
Now I want to change the time. I know the id of the schedule, but not the params.
How can I do it ?
- Can't delete and create again because I don't have the params
- I found no way to get a scheduled script infos even with its id...
- Could maintain a collection of all my running scripts, but painfull and prone to errors
Thanks !
Best Answer
C
Christian Gauthier
said
about 5 years ago
Eric,
As far as I know this is the only way to go for your case where you cannot reconstitute parameters from existing collections. But it's not that painfull to implement.
Here's something that maybe will fit your need, It as not been tested and compiled:
var Scheduler = {
schedule: function(eventShortCode, taskId, delayInSeconds, parameters){
var taskData = {
"id":taskId,
"eventShortCode":eventShortCode,
"parameters":parameters,
}
var taskData = Spark.runtimeCollection("ScheduledTask").findOne({"id":taskId});
if (taskData !== null){
throw "A task with id " + taskId + " is already scheduled";
}
Spark.getScheduler().inSeconds(eventShortCode, delayInSeconds, taskData, taskId);
}
reschedule: function(taskId, delayInSeconds){
var taskData = Spark.runtimeCollection("ScheduledTask").findOne({"id":taskId});
if (taskData === null){
throw "Cannot find scheduled task " + taskId;
}
Spark.getScheduler().cancel(taskId);
Spark.getScheduler().inSeconds(currentTask.eventShortCode, delayInSeconds, taskData, taskId);
}
//call this from your event function to remove the task data from the collection
taskComplete: function(taskId){
Spark.runtimeCollection("ScheduledTask").remove({"id":taskId});
}
}
schedule usage:
--------------------------
require("Scheduler");
//it must be a unique ID that you can recreate for task rescheduling
//player.getPlayerId() if taks are related to players, if you have multiple tasks for the same player append a suffix
var aUniqueTaskId = Spark.getPlayer().getPlayerId() + "_SEND_POWER_TASK";
Scheduler.schedule("SEND_POWER", aUniqueTaskId, 360, {"energy":3, "level":55, "color": "red"});
reschedule usage:
--------------------------
var aUniqueTaskId = Spark.getPlayer().getPlayerId() + "_SEND_POWER_TASK";
Scheduler.reschedule(aUniqueTaskId, 1800);
I think a collection of the scheduled scripts is a pretty good way to track these kinds of things.
If you find some aspect painful, let us know and we'll see if there is any way we can improve it.
You should be able to find the params you need here: Sparkscheduler.
Cheers,
Oisin
E
Eric Moncada
said
about 5 years ago
Hi ,
Sorry I'm not sure to understand.
Do you mean that I have to maintain a runtime collection with all the scripts I schedule ?
Then if I want to change the time, I query the runtime collection to find its parameters, then cancel the scheduled script, then create a new one, then update the runtime collection ?
This seems a little bit painfull and prone to errors.
Would be fine if there was an "update" method on SparkScheduler, or at least a "get" method to retrieve infos.
Once scheduled, we are in the dark...
C
Christian Gauthier
said
about 5 years ago
Answer
Eric,
As far as I know this is the only way to go for your case where you cannot reconstitute parameters from existing collections. But it's not that painfull to implement.
Here's something that maybe will fit your need, It as not been tested and compiled:
var Scheduler = {
schedule: function(eventShortCode, taskId, delayInSeconds, parameters){
var taskData = {
"id":taskId,
"eventShortCode":eventShortCode,
"parameters":parameters,
}
var taskData = Spark.runtimeCollection("ScheduledTask").findOne({"id":taskId});
if (taskData !== null){
throw "A task with id " + taskId + " is already scheduled";
}
Spark.getScheduler().inSeconds(eventShortCode, delayInSeconds, taskData, taskId);
}
reschedule: function(taskId, delayInSeconds){
var taskData = Spark.runtimeCollection("ScheduledTask").findOne({"id":taskId});
if (taskData === null){
throw "Cannot find scheduled task " + taskId;
}
Spark.getScheduler().cancel(taskId);
Spark.getScheduler().inSeconds(currentTask.eventShortCode, delayInSeconds, taskData, taskId);
}
//call this from your event function to remove the task data from the collection
taskComplete: function(taskId){
Spark.runtimeCollection("ScheduledTask").remove({"id":taskId});
}
}
schedule usage:
--------------------------
require("Scheduler");
//it must be a unique ID that you can recreate for task rescheduling
//player.getPlayerId() if taks are related to players, if you have multiple tasks for the same player append a suffix
var aUniqueTaskId = Spark.getPlayer().getPlayerId() + "_SEND_POWER_TASK";
Scheduler.schedule("SEND_POWER", aUniqueTaskId, 360, {"energy":3, "level":55, "color": "red"});
reschedule usage:
--------------------------
var aUniqueTaskId = Spark.getPlayer().getPlayerId() + "_SEND_POWER_TASK";
Scheduler.reschedule(aUniqueTaskId, 1800);
C
Christian Gauthier
said
about 5 years ago
oops, I forgot to add the data in the collection, here's the fix
var Scheduler = {
schedule: function(eventShortCode, taskId, delayInSeconds, parameters){
var taskData = {
"id":taskId,
"eventShortCode":eventShortCode,
"parameters":parameters,
}
var coll = Spark.runtimeCollection("ScheduledTask");
var taskData = coll.findOne({"id":taskId});
if (taskData !== null){
throw "A task with id " + taskId + " is already scheduled";
}
coll.insert(taskData);
Spark.getScheduler().inSeconds(eventShortCode, delayInSeconds, taskData, taskId);
},
reschedule: function(taskId, delayInSeconds){
var taskData = Spark.runtimeCollection("ScheduledTask").findOne({"id":taskId});
if (taskData === null){
throw "Cannot find scheduled task " + taskId;
}
Spark.getScheduler().cancel(taskId);
Spark.getScheduler().inSeconds(currentTask.eventShortCode, delayInSeconds, taskData, taskId);
},
//call this from your event function to remove the task data from the collection
taskComplete: function(taskId){
Spark.runtimeCollection("ScheduledTask").remove({"id":taskId});
}
}
schedule usage:
--------------------------
require("Scheduler");
//it must be a unique ID that you can recreate for task rescheduling
//player.getPlayerId() if taks are related to players, if you have multiple tasks for the same player append a suffix
var aUniqueTaskId = Spark.getPlayer().getPlayerId() + "_SEND_POWER_TASK";
Scheduler.schedule("SEND_POWER", aUniqueTaskId, 360, {"energy":3, "level":55, "color": "red"});
reschedule usage:
--------------------------
var aUniqueTaskId = Spark.getPlayer().getPlayerId() + "_SEND_POWER_TASK";
Scheduler.reschedule(aUniqueTaskId, 1800);
E
Eric Moncada
said
about 5 years ago
Hi Christian,
It makes sense to do this way, I'm going to implement it asap :)
Eric Moncada
I schedule a script with the scheduler, give the time, params and id.
Now I want to change the time. I know the id of the schedule, but not the params.
How can I do it ?
- Can't delete and create again because I don't have the params
- I found no way to get a scheduled script infos even with its id...
- Could maintain a collection of all my running scripts, but painfull and prone to errors
Thanks !
Eric,
As far as I know this is the only way to go for your case where you cannot reconstitute parameters from existing collections. But it's not that painfull to implement.
Here's something that maybe will fit your need, It as not been tested and compiled:
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi Eric,
I think a collection of the scheduled scripts is a pretty good way to track these kinds of things.
If you find some aspect painful, let us know and we'll see if there is any way we can improve it.
You should be able to find the params you need here: Sparkscheduler.
Cheers,
Oisin
Eric Moncada
Hi ,
Sorry I'm not sure to understand.
Do you mean that I have to maintain a runtime collection with all the scripts I schedule ?
Then if I want to change the time, I query the runtime collection to find its parameters, then cancel the scheduled script, then create a new one, then update the runtime collection ?
This seems a little bit painfull and prone to errors.
Would be fine if there was an "update" method on SparkScheduler, or at least a "get" method to retrieve infos.
Once scheduled, we are in the dark...
Christian Gauthier
Eric,
As far as I know this is the only way to go for your case where you cannot reconstitute parameters from existing collections. But it's not that painfull to implement.
Here's something that maybe will fit your need, It as not been tested and compiled:
Christian Gauthier
oops, I forgot to add the data in the collection, here's the fix
Eric Moncada
Hi Christian,
It makes sense to do this way, I'm going to implement it asap :)
Thanks !
Customer Support
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2486 topics