Skip to content

Commit 50c312e

Browse files
committed
docs: add an example how to create a task
1 parent 86c2d62 commit 50c312e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

examples/task_example.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from influxdb_client import InfluxDBClient, TaskCreateRequest
2+
3+
url = "http://localhost:8086"
4+
org = "my-org"
5+
bucket = "my-bucket"
6+
token = "my-token"
7+
8+
with InfluxDBClient(url=url, token=token, org=org, debug=True) as client:
9+
tasks_api = client.tasks_api()
10+
11+
flux = \
12+
'''
13+
option task = {{
14+
name: "{task_name}",
15+
every: 1d
16+
}}
17+
18+
from(bucket: "{from_bucket}")
19+
|> range(start: -task.every)
20+
|> filter(fn: (r) => (r._measurement == "m"))
21+
|> aggregateWindow(every: 1h, fn: mean)
22+
|> to(bucket: "{to_bucket}", org: "{org}")
23+
'''.format(task_name="my-task", from_bucket=bucket, to_bucket="to-my-bucket", org=org)
24+
25+
task_request = TaskCreateRequest(flux=flux, org=org, description="Task Description", status="active")
26+
task = tasks_api.create_task(task_create_request=task_request)
27+
print(task)

0 commit comments

Comments
 (0)