You are on page 1of 12

文档名称 文档密级

How to schedule job in FunctionGraph

This is the guidebook for using FunctionGraph to schedule the ECS. We


already prepared the script, and here is how the client can configure it.

1.1 Download index.zip function package, and change to your information.

Check the ECS ID here (if you have many ECS, you can use “,” to separate
them):

And check your project information here:

2023-8-17 华为保密信息,未经授权禁止扩散 第 1 页, 共 12 页
文档名称 文档密级

1.2 Edit the zip file, open index.py and adjust the value of the variable client to
the Region where you need to run this function
(https://developer.huaweicloud.com/intl/en-us/endpoint?all), save and
update the zip file.

2023-8-17 华为保密信息,未经授权禁止扩散 第 2 页, 共 12 页
文档名称 文档密级

1.3 Go to FunctionGraph console, click “Function List”, then choose “Create


Function”

It will show like this:

Set the function name


Set Runtime value to Phyton 3.6.
Click “Create Agency”

Open IAM console, and click “Create Agency”

2023-8-17 华为保密信息,未经授权禁止扩散 第 3 页, 共 12 页
文档名称 文档密级

Then set the name for the agency, choose “Cloud Service”, and choose the service
“FunctionGraph”, then add the permission as below:

Search “ECS”,and choose “ECS FullAccess”:

2023-8-17 华为保密信息,未经授权禁止扩散 第 4 页, 共 12 页
文档名称 文档密级

2023-8-17 华为保密信息,未经授权禁止扩散 第 5 页, 共 12 页
文档名称 文档密级

1.4 Back to FunctionGraph console, and click refresh , it will show the new
agency as below:

1.5 Click “Upload”, Local ZIP

Search for index.zip

2023-8-17 华为保密信息,未经授权禁止扩散 第 6 页, 共 12 页
文档名称 文档密级

1.6 Click “Configuration”, we have to set the configuration before we test this
function

Create the “Environment Variables” ecs_id_list, project_id:

Click “Save”, and it will show as below:

2023-8-17 华为保密信息,未经授权禁止扩散 第 7 页, 共 12 页
文档名称 文档密级

1.7 (Optional)Now we can configure the test event

Select the “timer-event-template”, and rename as “timer-start”:

2023-8-17 华为保密信息,未经授权禁止扩散 第 8 页, 共 12 页
文档名称 文档密级

It will show the template , but we have to adopt it, so you can copy this code
directly to that template, and save it:

{
"version": "v1.0",
"time": "2018-06-01T08:30:00+08:00",
"trigger_type": "TIMER",
"trigger_name": "Timer_001",
"user_event": "{\"operation\":\"startup\"}"
}

We can create another one:


{
"version": "v1.0",
"time": "2018-06-01T08:30:00+08:00",
"trigger_type": "TIMER",
"trigger_name": "Timer_001",
"user_event": "{\"operation\":\"shutdown\"}"
}

2023-8-17 华为保密信息,未经授权禁止扩散 第 9 页, 共 12 页
文档名称 文档密级

1.8 (Optional)Then we can test our environments (“Test” is for debugging):

Choose the timer and click “Test”, we can get the result as below:

1.9 After we set the events, we have to set the trigger for the events:

Click “Create Trigger” and rename as “Timer-start”, and choose “Cron

2023-8-17 华为保密信息,未经授权禁止扩散 第 10 页, 共 12 页
文档名称 文档密级

expression”, input your cron expression.


(If you don’t know how to generate the cron expression, you can use the online
tool like this: https://www.freeformatter.com/cron-expression-generator-
quartz.html)
0 30 10 * * ?  Executes a function at 10:40:00 every day.
Add this information to “Additional Information”:
{"operation": "startup"}

We can create another one “Timer-shutdown”:


Add the information as below to “Additional Information”:
{"operation": "shutdown"}

2023-8-17 华为保密信息,未经授权禁止扩散 第 11 页, 共 12 页
文档名称 文档密级

Then we can check the triggers we created, the trigger will execute
automatically:

2023-8-17 华为保密信息,未经授权禁止扩散 第 12 页, 共 12 页

You might also like