File: task_example.py

package info (click to toggle)
python-influxdb-client 1.40.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,216 kB
  • sloc: python: 60,236; sh: 64; makefile: 53
file content (33 lines) | stat: -rw-r--r-- 950 bytes parent folder | download | duplicates (2)
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
28
29
30
31
32
33
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)

    tasks = tasks_api.find_tasks_iter()

    # print all tasks id
    for task in tasks:
        print(task.id)