tencent cloud

Feedback

Quick Start

Last updated: 2024-01-13 11:19:29

    Overview

    This document describes the usage methods and computing capability of Batch.

    Prerequisites

    Complete preparations based on the instructions in Preparation, and learn how to configure the general part of the custom information.

    Viewing the Demo

    Note:
    Modify the general part of the custom information in 1_SimpleStart.py based on the instructions in Preparation.
    Open 1_SimpleStart.py in an editor.
    # custom (Change to your info)
    imageId = "img-m4q71qnf"
    Application = {
    "DeliveryForm": "LOCAL",
    "Command": " python -c \\"fib=lambda n:1 if n<=2 else fib(n-1)+fib(n-2); print(fib(20))\\" "
    }
    StdoutRedirectPath = "your cos path"
    StderrRedirectPath = "your cos path"
    All information except Application in the general part is described in Preparation. Set the parameters of Application based on the following table.
    Configuration Item
    Description
    DeliveryForm
    Three methods are available for delivering an application: software packaging, container image, and direct running within a CVM instance. LOCAL indicates direct running within a CVM instance.
    Command:
    The command for starting a job. In this example, a Python script is executed. Starting from 1, the script adds up the first 20 numbers of the Fibonacci sequence and outputs the result to StdOutput.

    Submitting a Job

    Run the following command to run the Python script. The demo encapsulates the job submission process by using Python scripts and the Batch command line tool.
    python 1_SimpleStart.py
    The returned result is as follows, indicating that the job is successfully submitted:
    {
    "RequestId": "393292f4-5583-48ad-a9f5-f673138ea637",
    "JobId": "job-o0xxxxxq7"
    }
    If the submit operation fails, check the returned value, or contact us.

    Viewing State

    Run the following command to view the execution status through DescribeJob:
    $ tccli batch DescribeJob --version 2017-03-12 --JobId job-xxx
    Note:
    --Replace job-xxx with the JobId that is returned after you submit the job.
    The returned result is as follows (some information is omitted):
    {
    "EndTime": "2019-10-08T04:06:58Z",
    "JobState": "SUCCEED",
    "TaskInstanceMetrics": {
    ...
    },
    "Zone": "ap-guangzhou-2",
    "TaskMetrics": {
    ...
    },
    "JobName": "TestJob",
    "Priority": 1,
    "RequestId": "7a5f4c94-1357-486c-9c48-8286ba01b5b2",
    "TaskSet": [
    ...
    ],
    "StateReason": null,
    "JobId": "job-o0xxxxxq7",
    "DependenceSet": [],
    "CreateTime": "2019-10-08T04:05:54Z"
    }
    The common values of JobState in the returned result are as follows:
    STARTING: Launching
    RUNNING: Running
    SUCCEED: Running successfully
    FAILED: Failed to run

    Viewing the Result

    1. Log in to the COS console. In the left sidebar, click Bucket List.
    2. Click the ID of the desired bucket, go to the object list page, and view the log files that store the execution results. See the figure below:
    
    If the job succeeds, view the standard output in stdout.job-xxx.xxxx.0.log. The content is as follows:
    6765
    If the job fails, view the standard error in stderr.job-xxx.xxxx.0.log. The content may be as follows:
    /bin/sh: -c: line 0: syntax error near unexpected token `('
    /bin/sh: -c: line 0: ` python -c \\"fib=lambda n:1 if n<=2 else fib(n-1)+fib(n-2); print(fib(20))\\" '
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support