All Products
Search
Document Center

Simple Log Service:Enable a scheduled SQL job

Last Updated:Jan 23, 2025

Call the EnableScheduledSQL API to enable a scheduled SQL job.

Prerequisites

  • Simple Log Service is activated.

  • Python is installed (see Install Python), a Python development environment is set up (see PyCharm), and a Python package management tool is installed (see pip).

    • Simple Log Service SDK for Python of the new version supports Python 3.7 and later.

    • You can run the python-V command to check the version of Python that is installed.

    • You can run the pip3 -V command to check the version of pip that is installed.

  • Simple Log Service SDK for Python of the new version is installed.

    • Run the following command in CLI to install Simple Log Service SDK for Python of the new version:

      pip install alibabacloud_sls20201230
    • After the installation is complete, run the following command to verify the installation:

      pip show alibabacloud_sls20201230
  • The ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured. For more information, see Configure environment variables in Linux, macOS, and Windows.

Parameter description

def enable_scheduled_sql(
        self,
        project: str,
        scheduled_sqlname: str,
) -> sls_20201230_models.EnableScheduledSQLResponse:

Request parameters

Parameter

Type

Required

Description

Example

project

String

No

The name of the project.

ali-test-project

scheduled_sqlname

String

No

The name of the scheduled SQL job.

test-001

Response parameters

For information about the response parameters, see EnableScheduledSQL.

Sample code

import os

from alibabacloud_sls20201230.client import Client as Sls20201230Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_sls20201230 import models as sls_20201230_models
from alibabacloud_tea_util.client import Client as UtilClient


def main():
    config = open_api_models.Config(
        # Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured.
        access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
        # Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured.
        access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
    )

    # Specify a Simple Log Service endpoint.
    config.endpoint = "cn-hangzhou.log.aliyuncs.com"
    client = Sls20201230Client(config)
    project = "ali-test-project"
    scheduled_sqlname = "test-001"

    try:
        response = client.enable_scheduled_sql(project, scheduled_sqlname)
        print(response)
    except Exception as error:
        print(error)
        print(error.data.get("Recommend"))
        UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    main()