12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- """
- A example workflow for task datax.
- This example will create a workflow named `task_datax`.
- `task_datax` is true workflow define and run task task_datax.
- You can create data sources `first_mysql` and `first_mysql` through UI.
- It creates a task to synchronize datax from the source database to the target database.
- """
- from pydolphinscheduler.core.process_definition import ProcessDefinition
- from pydolphinscheduler.tasks.datax import CustomDataX, DataX
- JSON_TEMPLATE = {
- "job": {
- "content": [
- {
- "reader": {
- "name": "mysqlreader",
- "parameter": {
- "username": "usr",
- "password": "pwd",
- "column": ["id", "name", "code", "description"],
- "splitPk": "id",
- "connection": [
- {
- "table": ["source_table"],
- "jdbcUrl": ["jdbc:mysql://127.0.0.1:3306/source_db"],
- }
- ],
- },
- },
- "writer": {
- "name": "mysqlwriter",
- "parameter": {
- "writeMode": "insert",
- "username": "usr",
- "password": "pwd",
- "column": ["id", "name"],
- "connection": [
- {
- "jdbcUrl": "jdbc:mysql://127.0.0.1:3306/target_db",
- "table": ["target_table"],
- }
- ],
- },
- },
- }
- ],
- "setting": {
- "errorLimit": {"percentage": 0, "record": 0},
- "speed": {"channel": 1, "record": 1000},
- },
- }
- }
- with ProcessDefinition(
- name="task_datax_example",
- tenant="tenant_exists",
- ) as pd:
-
-
-
-
- task1 = DataX(
- name="task_datax",
- datasource_name="first_mysql",
- datatarget_name="second_mysql",
- sql="select id, name, code, description from source_table",
- target_table="target_table",
- )
-
-
- task2 = CustomDataX(name="task_custom_datax", json=str(JSON_TEMPLATE))
- pd.run()
|