Custom command
You can run custom commands based on the component types. Function Compute provides components that support capabilities such as function deployment, application development, and project testing. You can use Serverless Devs together with the components to meet your business requirements.
The following sample code shows the content of a YAML description file of a resource of or an operation on an application.
edition: 3.0.0 # Command-line YAML specification version, following the Semantic Versioning specification
name: FullStack # Project name
access: xxx-account1
services:
backend: # service name
component: django-component # component name
props: # property value of the component
src: ./backend_src
url: url
user—frontend: # service name
component: vue-component # component name
props: # property value of the component
src: ./frontend_src_user
url: url
admin-frontend: # service name
component: vue-component # component name
props: # property value of the component
src: ./frontend_src_admin
url: url
The following information can be seen from the Yaml file:
- The name of the application is
FullStackand will use the keyxxx-account1; - The app has three services:
backendservice: uses thedjango-componentcomponentuser-frontendservice: uses thevue-componentcomponentadmin-frontendservice: usesvue-componentcomponent
If the custom commands supported by the django-component component and the vue-component component at this time are:
django-component | vue-component | |
|---|---|---|
deploy | support | support |
remove | support | support |
test | supported | not supported |
Then you can implement [application-level operations](#application-level operations) and [service-level operations](#service-level operations) through custom commands.
Application level operations
Under the current project, you can execute s [custom command] to implement the operation of applying latitude.
- When executing
s deployors remove, the components corresponding to the three servicesbackend,user-frontend, andadmin-frontendsupport thedeployandremovemethods, so at this time The system will follow the [service order defined by the Serverless User Model] (../../../spec/en/0.0.2/serverless_user_model/3.user_model.md#service order), and carry out the corresponding three services respectivelydeployorremoveoperation of the component; At this time, theexit codeof the system is 0; - When executing
s test, since the components corresponding to the two servicesuser-frontendandadmin-frontenddo not support thetestmethod, the system will execute the component corresponding tobackendat this time (django-component)testoperation; **At this time, the system will warn the two servicesuser-frontendandadmin-frontend, but no error will be reported, and the finalexit code` is 0;** - If any of the three services
backend,user-frontendandadmin-frontendhave an error during the execution of the relevant command, the system will report an error and terminate the next operation. At this time, theexit codeof the system is 101;
About Serverless Devs developer tools, related Exit Code, you can refer to Developer Tools Design Document
Service level operations
Under the current project, you can execute s [service name] [custom command] to implement service-level operations.
- Execute
s backend deploy, etc., you can performdeployrelated operations for the servicebackend. If the operation is successfully completed, theexit codeof the system is 0; otherwise, an error occurs, and theexit codeof the system ` is 101; - Execute
s admin-frontend test, because thetestmethod corresponding to the serviceadmin-frontenddoes not exist, At this time, the system will consider that the component method is not found, and theexit codeof the system is 100;
Precautions
In the above application level operations and service level operations, it is not difficult to find that some components do not include corresponding methods, but in application level operations and service level operation are different. The design idea here is mainly to ensure the fluency of application-level operation. So the rules are usually as follows:
- Application level operation is more of a batch operation, which will follow the service order defined by Serverless User Model to operate all services under the application separately; therefore, if there is a component corresponding to a service that does not include the current method, the "batch operation" will be used as the reason to skip. This service, continue to execute after warning, At this time, the
exit codeof the system is 0; - Service level operation is more of a specific operation for a service under a certain application. If the corresponding method cannot be found at this time, it means that this operation is meaningless. It will wake up the error report, At this time, the
exit codeof the system is 100;