forked from influxdata/influxdb-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_example.py
27 lines (22 loc) · 837 Bytes
/
task_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from influxdb_client import InfluxDBClient, TaskCreateRequest
url = "http://localhost:8086"
org = "my-org"
bucket = "my-bucket"
token = "my-token"
with InfluxDBClient(url=url, token=token, org=org, debug=True) as client:
tasks_api = client.tasks_api()
flux = \
'''
option task = {{
name: "{task_name}",
every: 1d
}}
from(bucket: "{from_bucket}")
|> range(start: -task.every)
|> filter(fn: (r) => (r._measurement == "m"))
|> aggregateWindow(every: 1h, fn: mean)
|> to(bucket: "{to_bucket}", org: "{org}")
'''.format(task_name="my-task", from_bucket=bucket, to_bucket="to-my-bucket", org=org)
task_request = TaskCreateRequest(flux=flux, org=org, description="Task Description", status="active")
task = tasks_api.create_task(task_create_request=task_request)
print(task)