Update a scheduled SQL job
Call the UpdateScheduledSQL operation to update a scheduled SQL job by using the Simple Log Service SDK for Python.
The Simple Log Service SDK no longer updates APIs related to scheduled SQL. Use the Alibaba Cloud SDK to manage scheduled SQL:
On the CreateScheduledSQL API debugging page in the Alibaba Cloud OpenAPI Explorer, click the SDK Example tab on the right panel. Select your target language (Java, TypeScript, Go, PHP, Python, .NET, C++, etc.) to view the corresponding SDK sample code. You can click Run Example for online debugging or Download Full Project.
Prerequisites
-
Simple Log Service is activated. For more information, see Activate Simple Log Service.
-
The Simple Log Service SDK for Python is initialized. For more information, see Initialize Simple Log Service SDK for Python.
Parameters
def update_scheduled_sql(self, project_name, scheduled_sql):
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
|
project_name |
String |
Yes |
The name of the Project. |
ali-test-project |
|
scheduled_sql |
object |
Yes |
The configuration of the scheduled SQL job. |
- |
scheduled_sql parameters
|
Parameter |
Type |
Required |
Description |
Example |
|
name |
String |
Yes |
The scheduled SQL job name. Requirements:
|
test-001 |
|
displayName |
String |
Yes |
The display name of the job. |
test-001 |
|
description |
String |
No |
The description of the job. |
Create a scheduled SQL job. |
|
schedule |
object |
Yes |
The scheduling configuration of the job. |
- |
|
configuration |
object |
Yes |
The configuration of the scheduled SQL job. |
- |
schedule parameters
|
Parameter |
Type |
Required |
Description |
Example |
|
type |
String |
Yes |
The scheduling type. Valid values:
|
Cron |
|
cronExpression |
String |
No |
The cron expression. |
0/5 * * * * |
|
runImmediately |
bool |
No |
Whether to run the job immediately after creation. |
False |
|
timeZone |
String |
No |
The time zone for the cron expression. Defaults to UTC+8. |
+0800 |
|
delay |
int |
No |
The delay before the job runs, in seconds. Maximum: 86,400. |
4 |
|
interval |
String |
No |
The execution interval when |
1m |
configuration parameters
|
Parameter |
Type |
Required |
Description |
Example |
|
script |
String |
Yes |
The query and analysis statement for the scheduled SQL job. |
* | select * |
|
sqlType |
String |
Yes |
The type of the SQL statement. |
searchQuery |
|
destEndpoint |
String |
Yes |
The destination endpoint. |
cn-hangzhou-intranet.log.aliyuncs.com |
|
destProject |
String |
Yes |
The destination Project. |
project-demo |
|
sourceLogstore |
String |
Yes |
The source Logstore. |
source-logstore-demo |
|
destLogstore |
String |
Yes |
The destination Logstore. Warning
Do not set the destination to the same store as the source. This can cause a write loop that incurs additional storage and traffic costs. You are responsible for the resulting resource consumption and costs. |
dest-logstore-demo |
|
roleArn |
String |
Yes |
The RAM role ARN to assume for running the SQL query. |
acs:ram::123456789:role/aliyunlogetlrole |
|
destRoleArn |
String |
Yes |
The RAM role ARN to assume for writing data to the destination. |
acs:ram::123456789:role/aliyunlogetlrole |
|
fromTimeExpr |
String |
Yes |
The start of the SQL time window. |
@m-1m |
|
toTimeExpr |
String |
Yes |
The end of the SQL time window. |
@m |
|
maxRunTimeInSeconds |
int |
Yes |
The SQL query timeout, in seconds. Valid values: 60 to 1,800. |
600 |
|
resourcePool |
String |
Yes |
The resource pool type. |
enhanced |
|
maxRetries |
int |
Yes |
The maximum number of retries after an SQL query times out. Valid values: 1 to 100. |
20 |
|
fromTime |
int |
Yes |
The start time. Create a scheduled SQL job to import data from a Logstore to a Metricstore. |
1712592000 |
|
toTime |
int |
Yes |
The end time. Create a scheduled SQL job to import data from a Logstore to a Metricstore. |
0 |
|
dataFormat |
String |
Yes |
The data transformation format. Valid values: |
log2log |
|
parameters |
object |
Yes |
The SQL configuration. Create a scheduled SQL job to import data from a Logstore to a Metricstore. |
|
Response parameters
See UpdateScheduledSQL.
Sample code
import os
import time
from aliyun.log import LogClient
from aliyun.log.scheduled_sql import *
accessKeyId = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '') # The AccessKey ID.
accessKeySecret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '') # The AccessKey secret.
endpoint = "cn-hangzhou.log.aliyuncs.com" # The endpoint of the project's region.
roleArn = "acs:ram::141******5616316:role/aliyunserviceroleforslsaudit" # The role ARN.
project = "demo-test-project" # The source project name.
source_logstore = "test-logstore" # The source Logstore name.
source_metricstore = "" # The source Metricstore name.
dest_endpoint = "cn-hangzhou.log.aliyuncs.com" # The endpoint of the destination project's region.
dest_role_arn = "acs:ram::141******5616316:role/aliyunserviceroleforslsaudit" # The destination role ARN.
dest_project = "demo-test-project" # The destination project name.
dest_logstore = "test-logstore2" # The destination Logstore name.
dest_metricstore = "" # The destination Metricstore name.
from_time = int(time.time()) - 300 # The start time of the scheduled SQL job.
job_name = "test-001" # The job name.
display_name = "test-001-update" # The display name.
description = "Modify a scheduled SQL job" # The description.
script = "* | select *" # The SQL script.
promql = "* | select promql_query_range('key{}') from metrics limit 1000" # The PromQL script.
instance_id = "" # The instance ID of the scheduled SQL job.
delay_seconds = 0 # The delay for the scheduled SQL job in seconds.
# Three possible values for the data_format variable: "log2log", "log2metric", and "metric2metric".
data_format = "log2log"
# Possible values for the schedule_type variable: "FixedRate", "Daily", "Weekly", "Hourly", and "Cron".
# schedule_type = "FixedRate"
schedule_type = "FixedRate"
client = LogClient(endpoint, accessKeyId, accessKeySecret)
def update_schedule_sql():
scheduled_sql_config = get_schedule_sql()
configuration = scheduled_sql_config['configuration']
schedule = scheduled_sql_config['schedule']
configuration['fromTimeExpr'] = '@m-3m'
configuration['maxRetries'] = 25
schedule['type'] = 'Cron'
schedule['timeZone'] = '+0800'
schedule['interval'] = ''
schedule['dayOfWeek'] = ''
schedule['hour'] = ''
schedule['cronExpression'] = '*/2 * * * *'
schedule = dict_to_schedule_rule(schedule)
configuration = dict_to_scheduled_sql_config(configuration)
schedule_sql = ScheduledSQL()
schedule_sql.setSchedule(schedule)
schedule_sql.setConfiguration(configuration)
schedule_sql.setName(job_name)
schedule_sql.setDisplayName(display_name)
schedule_sql.setDescription(description)
update_schedule_sql_response = client.update_scheduled_sql(dest_project, schedule_sql)
update_schedule_sql_response.log_print()
def get_schedule_sql():
get_schedule_sql_response = client.get_scheduled_sql(dest_project, job_name)
scheduled_sql_config = get_schedule_sql_response.scheduled_sql_config
return scheduled_sql_config
if __name__ == "__main__":
update_schedule_sql()
pass
Sample response
UpdateScheduledSqlJobResponse:
headers: {'Server': 'AliyunSLS', 'Content-Length': '0', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Fri, 01 Nov 2024 08:18:08 GMT', 'x-log-time': '1730449088', 'x-log-requestid': '67248EC069A98605C79EED79'}
Process finished with exit code 0
Related documents
-
API operations for managing scheduled SQL jobs: