I am trying to use the utils.scheduler.CreateEnvTask
endpoint in Jelastic Cloud API to schedule an environment shutdown after a delay. However, I keep encountering errors, and I cannot find detailed documentation or example on how to properly configure the script parameter.
I want to schedule a task that will automatically stop my environment 1 hour after its creation. Based on the Jelastic API documentation, I am using the following curl request:
curl -X POST "JELASTIC_API_URL/utils/scheduler/rest/createenvtask" \
-d "session=API_ACCESS_TOKEN" \
-d "envName=ENV_NAME" \
-d "script=environment.control.stopenv" \
-d "trigger=once_delay:3600000" \
-H "Content-Type: application/x-www-form-urlencoded"
This request returns the following error:
{"result":1702,"debug":{"cpu":{"usage":"0","time":17},"time":436},"source":"hx-core","error":"script = environment.control.stopenv not found"}
It looks like the API does not recognize environment.control.stopenv as a valid script.
What I have tried
Checked my token has the necessary rights to stop an environment.
Tested different script formats
Tried "script": "environment.control.rest.stopenv"
Tried providing a full URL to a .jps script hosted on GitHub (but the slashes / were replaced by dots . in the error message).
Verified documentations (jelastic and virtuozzo), but it lacks detailed examples on the script parameter for CreateEnvTask.
Asked my jelastic provider, but no support about the jelastic api
Additional Observation:
When I make a typo in the endpoint name (e.g., changing CreateEnvTask to CreateEnvTasks), I get a similar error:
{"result":1702,"debug":{"cpu":{"usage":"0","time":36},"time":155},"response":null,"source":"hx-core","error":"script = utils.scheduler.rest.createenvtasks,environment.control.stopenv not found"}
This makes me think that the issue might be related to how Jelastic constructs the script path internally, rather than the script itself being missing. So I misunderstanding how script paths are resolved.
My Questions
What is the correct way to reference built-in Jelastic scripts in utils.scheduler.CreateEnvTask?
Is there a specific format required for the script parameter?
Despite multiple attempts, I haven’t been able to get this working. Any guidance or working example would be greatly appreciated!
I am trying to use the utils.scheduler.CreateEnvTask
endpoint in Jelastic Cloud API to schedule an environment shutdown after a delay. However, I keep encountering errors, and I cannot find detailed documentation or example on how to properly configure the script parameter.
I want to schedule a task that will automatically stop my environment 1 hour after its creation. Based on the Jelastic API documentation, I am using the following curl request:
curl -X POST "JELASTIC_API_URL/utils/scheduler/rest/createenvtask" \
-d "session=API_ACCESS_TOKEN" \
-d "envName=ENV_NAME" \
-d "script=environment.control.stopenv" \
-d "trigger=once_delay:3600000" \
-H "Content-Type: application/x-www-form-urlencoded"
This request returns the following error:
{"result":1702,"debug":{"cpu":{"usage":"0","time":17},"time":436},"source":"hx-core","error":"script = environment.control.stopenv not found"}
It looks like the API does not recognize environment.control.stopenv as a valid script.
What I have tried
Checked my token has the necessary rights to stop an environment.
Tested different script formats
Tried "script": "environment.control.rest.stopenv"
Tried providing a full URL to a .jps script hosted on GitHub (but the slashes / were replaced by dots . in the error message).
Verified documentations (jelastic and virtuozzo), but it lacks detailed examples on the script parameter for CreateEnvTask.
Asked my jelastic provider, but no support about the jelastic api
Additional Observation:
When I make a typo in the endpoint name (e.g., changing CreateEnvTask to CreateEnvTasks), I get a similar error:
{"result":1702,"debug":{"cpu":{"usage":"0","time":36},"time":155},"response":null,"source":"hx-core","error":"script = utils.scheduler.rest.createenvtasks,environment.control.stopenv not found"}
This makes me think that the issue might be related to how Jelastic constructs the script path internally, rather than the script itself being missing. So I misunderstanding how script paths are resolved.
My Questions
What is the correct way to reference built-in Jelastic scripts in utils.scheduler.CreateEnvTask?
Is there a specific format required for the script parameter?
Despite multiple attempts, I haven’t been able to get this working. Any guidance or working example would be greatly appreciated!
Share Improve this question asked Mar 31 at 11:00 YaleYale 214 bronze badges1 Answer
Reset to default 1Asked my jelastic provider, but no support about the jelastic api
That's a shame... Maybe find a different one that can support you properly?
As for your question itself, I recommend to take a look at the database-backup-addon for an example of how to call this API endpoint correctly:
me.scheduleBackup = function scheduleBackup() {
var quartz = new CronToQuartzConverter().convert(config.cronTime);
for (var i = quartz.length; i--;) {
var resp = jelastic.utils.scheduler.CreateEnvTask({
appid: appid,
envName: config.envName,
session: session,
script: config.scriptName,
trigger: "cron:" + quartz[i],
params: { task: 1, action : "backup" }
});
if (resp.result !== 0) return resp;
}
return { result: 0 };
};
Or even the start-stop-scheduler as a more closely related example to what you're trying to achieve.
You can see here that the script is supposed to be one you create:
resp = api.dev.scripting.CreateScript({ appid: targetAppid, name: createServiceScriptName, type: 'js', code: this.code });
And then you pass that same script name to your scheduler task:
return api.utils.scheduler.CreateEnvTask({
appid: targetAppid,
session: session,
envName: envName,
script: createServiceScriptName,
trigger: "once_delay:1000",
description: "configure start-stop addon task for ${env.envName}",
params: {
isTask: true,
name: name,
url: url,
start: getParam("start"),
stop: getParam("stop"),
action: getParam("action")
}
});
Hope that helps get you in the right direction.