-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathTasksApi.cs
1332 lines (1167 loc) · 60.7 KB
/
TasksApi.cs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using InfluxDB.Client.Api.Domain;
using InfluxDB.Client.Api.Service;
using InfluxDB.Client.Core;
namespace InfluxDB.Client
{
public interface ITasksApi
{
/// <summary>
/// Creates a new task. The <see cref="InfluxDB.Client.Api.Domain.TaskType"/> has to have defined a cron or a every repetition
/// by the <a href="http://bit.ly/option-statement">option statement</a>.
/// <example>
/// This sample shows how to specify every repetition
/// <code>
/// option task = {
/// name: "mean",
/// every: 1h,
/// }
///
/// from(bucket:"metrics/autogen")
/// |> range(start:-task.every)
/// |> group(columns:["level"])
/// |> mean()
/// |> yield(name:"mean")
/// </code>
/// </example>
/// </summary>
/// <param name="task">task to create (required)</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Created Task</returns>
/// <exception cref="NotImplementedException"></exception>
Task<TaskType> CreateTaskAsync(TaskType task, CancellationToken cancellationToken = default);
/// <summary>
/// Create a new task.
/// </summary>
/// <param name="taskCreateRequest">task to create (required)</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Created Task</returns>
Task<TaskType> CreateTaskAsync(TaskCreateRequest taskCreateRequest,
CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new task with task repetition by cron. The <see cref="TaskType.Flux" /> is without a cron or a every
/// repetition.
/// The repetition is automatically append to the <a href="http://bit.ly/option-statement">option statement</a>.
/// </summary>
/// <param name="name">description of the task</param>
/// <param name="flux">the Flux script to run for this task</param>
/// <param name="cron">a task repetition schedule in the form '* * * * * *'</param>
/// <param name="organization">the organization that owns this Task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
Task<TaskType> CreateTaskCronAsync(string name, string flux, string cron,
Organization organization, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new task with task repetition by cron. The <see cref="TaskType.Flux" /> is without a cron or a every
/// repetition.
/// The repetition is automatically append to the <a href="http://bit.ly/option-statement">option statement</a>.
/// </summary>
/// <param name="name">description of the task</param>
/// <param name="flux">the Flux script to run for this task</param>
/// <param name="cron">a task repetition schedule in the form '* * * * * *'</param>
/// <param name="orgId">the organization ID that owns this Task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
Task<TaskType> CreateTaskCronAsync(string name, string flux, string cron,
string orgId, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new task with task repetition by duration expression ("1h", "30s"). The <see cref="TaskType.Flux" /> is
/// without a cron or a every repetition.
/// The repetition is automatically append to the <a href="http://bit.ly/option-statement">option statement</a>.
/// </summary>
/// <param name="name">description of the task</param>
/// <param name="flux">the Flux script to run for this task</param>
/// <param name="every">a task repetition by duration expression</param>
/// <param name="organization">the organization that owns this Task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Created Task</returns>
/// <exception cref="NotImplementedException"></exception>
Task<TaskType> CreateTaskEveryAsync(string name, string flux, string every,
Organization organization, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new task with task repetition by duration expression ("1h", "30s"). The <see cref="TaskType.Flux" /> is
/// without a cron or a every repetition.
/// The repetition is automatically append to the <a href="http://bit.ly/option-statement">option statement</a>.
/// </summary>
/// <param name="name">description of the task</param>
/// <param name="flux">the Flux script to run for this task</param>
/// <param name="every">a task repetition by duration expression</param>
/// <param name="orgId">the organization ID that owns this Task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Created Task</returns>
/// <exception cref="NotImplementedException"></exception>
Task<TaskType> CreateTaskEveryAsync(string name, string flux, string every,
string orgId, CancellationToken cancellationToken = default);
/// <summary>
/// Update a task. This will cancel all queued runs.
/// </summary>
/// <param name="task">task update to apply</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>task updated</returns>
Task<TaskType> UpdateTaskAsync(TaskType task, CancellationToken cancellationToken = default);
/// <summary>
/// Update a task. This will cancel all queued runs.
/// </summary>
/// <param name="taskId">ID of task to get</param>
/// <param name="request">task update to apply</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>task updated</returns>
Task<TaskType> UpdateTaskAsync(string taskId, TaskUpdateRequest request,
CancellationToken cancellationToken = default);
/// <summary>
/// Delete a task.
/// </summary>
/// <param name="taskId">ID of task to delete</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>task deleted</returns>
Task DeleteTaskAsync(string taskId, CancellationToken cancellationToken = default);
/// <summary>
/// Delete a task.
/// </summary>
/// <param name="task">task to delete</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>task deleted</returns>
Task DeleteTaskAsync(TaskType task, CancellationToken cancellationToken = default);
/// <summary>
/// Clone a task.
/// </summary>
/// <param name="taskId">ID of task to clone</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>cloned task</returns>
Task<TaskType> CloneTaskAsync(string taskId, CancellationToken cancellationToken = default);
/// <summary>
/// Clone a task.
/// </summary>
/// <param name="task">task to clone</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>cloned task</returns>
Task<TaskType> CloneTaskAsync(TaskType task, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieve a task.
/// </summary>
/// <param name="taskId">ID of task to get</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>task details</returns>
Task<TaskType> FindTaskByIdAsync(string taskId, CancellationToken cancellationToken = default);
/// <summary>
/// Lists tasks, limit 100.
/// </summary>
/// <param name="user">filter tasks to a specific user</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>A list of tasks</returns>
Task<List<TaskType>> FindTasksByUserAsync(User user, CancellationToken cancellationToken = default);
/// <summary>
/// Lists tasks, limit 100.
/// </summary>
/// <param name="userId">filter tasks to a specific user ID</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>A list of tasks</returns>
Task<List<TaskType>> FindTasksByUserIdAsync(string userId, CancellationToken cancellationToken = default);
/// <summary>
/// Lists tasks, limit 100.
/// </summary>
/// <param name="organization">filter tasks to a specific organization</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>A list of tasks</returns>
Task<List<TaskType>> FindTasksByOrganizationAsync(Organization organization,
CancellationToken cancellationToken = default);
/// <summary>
/// Lists tasks, limit 100.
/// </summary>
/// <param name="orgId">filter tasks to a specific organization ID</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>A list of tasks</returns>
Task<List<TaskType>> FindTasksByOrganizationIdAsync(string orgId,
CancellationToken cancellationToken = default);
/// <summary>
/// Lists tasks, limit 100.
/// </summary>
/// <param name="afterId">returns tasks after specified ID</param>
/// <param name="userId">filter tasks to a specific user ID</param>
/// <param name="orgId">filter tasks to a specific organization ID</param>
/// <param name="org">Filter tasks to a specific organization name. (optional)</param>
/// <param name="name">Returns task with a specific name. (optional)</param>
/// <param name="limit">The number of tasks to return (optional, default to 100)</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>A list of tasks</returns>
Task<List<TaskType>> FindTasksAsync(string afterId = null, string userId = null,
string orgId = null, string org = null, string name = null, int? limit = null,
CancellationToken cancellationToken = default);
/// <summary>
/// List all members of a task.
/// </summary>
/// <param name="task">task of the members</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the List all members of a task</returns>
Task<List<ResourceMember>> GetMembersAsync(TaskType task, CancellationToken cancellationToken = default);
/// <summary>
/// List all members of a task.
/// </summary>
/// <param name="taskId">ID of task to get members</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the List all members of a task</returns>
Task<List<ResourceMember>> GetMembersAsync(string taskId,
CancellationToken cancellationToken = default);
/// <summary>
/// Add a task member.
/// </summary>
/// <param name="member">the member of a task</param>
/// <param name="task">the task of a member</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>created mapping</returns>
Task<ResourceMember> AddMemberAsync(User member, TaskType task,
CancellationToken cancellationToken = default);
/// <summary>
/// Add a task member.
/// </summary>
/// <param name="memberId">the ID of a member</param>
/// <param name="taskId">the ID of a task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>created mapping</returns>
Task<ResourceMember> AddMemberAsync(string memberId, string taskId,
CancellationToken cancellationToken = default);
/// <summary>
/// Removes a member from a task.
/// </summary>
/// <param name="member">the member of a task</param>
/// <param name="task">the task of a member</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>member removed</returns>
Task DeleteMemberAsync(User member, TaskType task, CancellationToken cancellationToken = default);
/// <summary>
/// Removes a member from a task.
/// </summary>
/// <param name="memberId">the ID of a member</param>
/// <param name="taskId">the ID of a task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>member removed</returns>
Task DeleteMemberAsync(string memberId, string taskId, CancellationToken cancellationToken = default);
/// <summary>
/// List all owners of a task.
/// </summary>
/// <param name="task">task of the owners</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the List all owners of a task</returns>
Task<List<ResourceOwner>> GetOwnersAsync(TaskType task, CancellationToken cancellationToken = default);
/// <summary>
/// List all owners of a task.
/// </summary>
/// <param name="taskId">ID of a task to get owners</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the List all owners of a task</returns>
Task<List<ResourceOwner>> GetOwnersAsync(string taskId,
CancellationToken cancellationToken = default);
/// <summary>
/// Add a task owner.
/// </summary>
/// <param name="owner">the owner of a task</param>
/// <param name="task">the task of a owner</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>created mapping</returns>
Task<ResourceOwner> AddOwnerAsync(User owner, TaskType task,
CancellationToken cancellationToken = default);
/// <summary>
/// Add a task owner.
/// </summary>
/// <param name="ownerId">the ID of a owner</param>
/// <param name="taskId">the ID of a task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>created mapping</returns>
Task<ResourceOwner> AddOwnerAsync(string ownerId, string taskId,
CancellationToken cancellationToken = default);
/// <summary>
/// Removes a owner from a task.
/// </summary>
/// <param name="owner">the owner of a task</param>
/// <param name="task">the task of a owner</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>owner removed</returns>
Task DeleteOwnerAsync(User owner, TaskType task, CancellationToken cancellationToken = default);
/// <summary>
/// Removes a owner from a task.
/// </summary>
/// <param name="ownerId">the ID of a owner</param>
/// <param name="taskId">the ID of a task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>owner removed</returns>
Task DeleteOwnerAsync(string ownerId, string taskId, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieve all logs for a task.
/// </summary>
/// <param name="task">task to get logs for</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the list of all logs for a task</returns>
Task<List<LogEvent>> GetLogsAsync(TaskType task, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieve all logs for a task.
/// </summary>
/// <param name="taskId">ID of task to get logs for</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the list of all logs for a task</returns>
Task<List<LogEvent>> GetLogsAsync(string taskId, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieve list of run records for a task.
/// </summary>
/// <param name="task"> task to get runs for</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the list of run records for a task</returns>
Task<List<Run>> GetRunsAsync(TaskType task, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieve list of run records for a task.
/// </summary>
/// <param name="task"> task to get runs for</param>
/// <param name="afterTime">filter runs to those scheduled after this time</param>
/// <param name="beforeTime">filter runs to those scheduled before this time</param>
/// <param name="limit">the number of runs to return. Default value: 20.</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the list of run records for a task</returns>
Task<List<Run>> GetRunsAsync(TaskType task, DateTime? afterTime,
DateTime? beforeTime, int? limit, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieve list of run records for a task.
/// </summary>
/// <param name="taskId">ID of task to get runs for</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the list of run records for a task</returns>
Task<List<Run>> GetRunsAsync(string taskId, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieve list of run records for a task.
/// </summary>
/// <param name="taskId">ID of task to get runs for</param>
/// <param name="afterTime">filter runs to those scheduled after this time</param>
/// <param name="beforeTime">filter runs to those scheduled before this time</param>
/// <param name="limit">the number of runs to return. Default value: 20.</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the list of run records for a task</returns>
Task<List<Run>> GetRunsAsync(string taskId,
DateTime? afterTime, DateTime? beforeTime, int? limit, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieve a single run record for a task.
/// </summary>
/// <param name="taskId">ID of task to get runs for</param>
/// <param name="runId">ID of run</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>a single run record for a task</returns>
Task<Run> GetRunAsync(string taskId, string runId, CancellationToken cancellationToken = default);
/// <summary>
/// Retry a task run.
/// </summary>
/// <param name="run">the run to retry</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the executed run</returns>
Task<Run> RetryRunAsync(Run run, CancellationToken cancellationToken = default);
/// <summary>
/// Retry a task run.
/// </summary>
/// <param name="taskId">ID of task with the run to retry</param>
/// <param name="runId">ID of run to retry</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the executed run</returns>
Task<Run> RetryRunAsync(string taskId, string runId, CancellationToken cancellationToken = default);
/// <summary>
/// Cancels a currently running run.
/// </summary>
/// <param name="run">the run to cancel</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns></returns>
Task CancelRunAsync(Run run, CancellationToken cancellationToken = default);
/// <summary>
/// Cancels a currently running run.
/// </summary>
/// <param name="taskId">ID of task with the run to cancel</param>
/// <param name="runId">ID of run to cancel</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns></returns>
Task CancelRunAsync(string taskId, string runId, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieve all logs for a run.
/// </summary>
/// <param name="run">the run to gets logs for it</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the list of all logs for a run</returns>
Task<List<LogEvent>> GetRunLogsAsync(Run run, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieve all logs for a run.
/// </summary>
/// <param name="taskId">ID of task to get run logs for it</param>
/// <param name="runId">ID of run to get logs for it</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the list of all logs for a run</returns>
Task<List<LogEvent>> GetRunLogsAsync(string taskId, string runId,
CancellationToken cancellationToken = default);
/// <summary>
/// List all labels of a Task.
/// </summary>
/// <param name="task">a Task of the labels</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the List all labels of a Task</returns>
Task<List<Label>> GetLabelsAsync(TaskType task, CancellationToken cancellationToken = default);
/// <summary>
/// List all labels of a Task.
/// </summary>
/// <param name="taskId">ID of a Task to get labels</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the List all labels of a Task</returns>
Task<List<Label>> GetLabelsAsync(string taskId, CancellationToken cancellationToken = default);
/// <summary>
/// Add a Task label.
/// </summary>
/// <param name="label">the label of a Task</param>
/// <param name="task">a Task of a label</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>added label</returns>
Task<Label> AddLabelAsync(Label label, TaskType task, CancellationToken cancellationToken = default);
/// <summary>
/// Add a Task label.
/// </summary>
/// <param name="labelId">the ID of a label</param>
/// <param name="taskId">the ID of a Task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>added label</returns>
Task<Label> AddLabelAsync(string labelId, string taskId,
CancellationToken cancellationToken = default);
/// <summary>
/// Removes a label from a Task.
/// </summary>
/// <param name="label">the label of a Task</param>
/// <param name="task">a Task of a owner</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>delete has been accepted</returns>
Task DeleteLabelAsync(Label label, TaskType task, CancellationToken cancellationToken = default);
/// <summary>
/// Removes a label from a Task.
/// </summary>
/// <param name="labelId">the ID of a label</param>
/// <param name="taskId">the ID of a Task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>delete has been accepted</returns>
Task DeleteLabelAsync(string labelId, string taskId, CancellationToken cancellationToken = default);
}
public class TasksApi : ITasksApi
{
private readonly TasksService _service;
protected internal TasksApi(TasksService service)
{
Arguments.CheckNotNull(service, nameof(service));
_service = service;
}
/// <summary>
/// Creates a new task. The <see cref="InfluxDB.Client.Api.Domain.TaskType"/> has to have defined a cron or a every repetition
/// by the <a href="http://bit.ly/option-statement">option statement</a>.
/// <example>
/// This sample shows how to specify every repetition
/// <code>
/// option task = {
/// name: "mean",
/// every: 1h,
/// }
///
/// from(bucket:"metrics/autogen")
/// |> range(start:-task.every)
/// |> group(columns:["level"])
/// |> mean()
/// |> yield(name:"mean")
/// </code>
/// </example>
/// </summary>
/// <param name="task">task to create (required)</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Created Task</returns>
/// <exception cref="NotImplementedException"></exception>
public Task<TaskType> CreateTaskAsync(TaskType task, CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(task, nameof(task));
var status = (TaskStatusType)Enum.Parse(typeof(TaskStatusType), task.Status.ToString());
var taskCreateRequest = new TaskCreateRequest(task.OrgID, task.Org, status,
task.Flux, task.Description);
return CreateTaskAsync(taskCreateRequest, cancellationToken);
}
/// <summary>
/// Create a new task.
/// </summary>
/// <param name="taskCreateRequest">task to create (required)</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Created Task</returns>
public Task<TaskType> CreateTaskAsync(TaskCreateRequest taskCreateRequest,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(taskCreateRequest, nameof(taskCreateRequest));
return _service.PostTasksAsync(taskCreateRequest, cancellationToken: cancellationToken);
}
/// <summary>
/// Creates a new task with task repetition by cron. The <see cref="TaskType.Flux" /> is without a cron or a every
/// repetition.
/// The repetition is automatically append to the <a href="http://bit.ly/option-statement">option statement</a>.
/// </summary>
/// <param name="name">description of the task</param>
/// <param name="flux">the Flux script to run for this task</param>
/// <param name="cron">a task repetition schedule in the form '* * * * * *'</param>
/// <param name="organization">the organization that owns this Task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public Task<TaskType> CreateTaskCronAsync(string name, string flux, string cron,
Organization organization, CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(name, nameof(name));
Arguments.CheckNonEmptyString(flux, nameof(flux));
Arguments.CheckNonEmptyString(cron, nameof(cron));
Arguments.CheckNotNull(organization, nameof(organization));
return CreateTaskCronAsync(name, flux, cron, organization.Id, cancellationToken);
}
/// <summary>
/// Creates a new task with task repetition by cron. The <see cref="TaskType.Flux" /> is without a cron or a every
/// repetition.
/// The repetition is automatically append to the <a href="http://bit.ly/option-statement">option statement</a>.
/// </summary>
/// <param name="name">description of the task</param>
/// <param name="flux">the Flux script to run for this task</param>
/// <param name="cron">a task repetition schedule in the form '* * * * * *'</param>
/// <param name="orgId">the organization ID that owns this Task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public Task<TaskType> CreateTaskCronAsync(string name, string flux, string cron,
string orgId, CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(name, nameof(name));
Arguments.CheckNonEmptyString(flux, nameof(flux));
Arguments.CheckNonEmptyString(cron, nameof(cron));
Arguments.CheckNonEmptyString(orgId, nameof(orgId));
var task = CreateTaskAsync(name, flux, null, cron, orgId);
return CreateTaskAsync(task, cancellationToken);
}
/// <summary>
/// Creates a new task with task repetition by duration expression ("1h", "30s"). The <see cref="TaskType.Flux" /> is
/// without a cron or a every repetition.
/// The repetition is automatically append to the <a href="http://bit.ly/option-statement">option statement</a>.
/// </summary>
/// <param name="name">description of the task</param>
/// <param name="flux">the Flux script to run for this task</param>
/// <param name="every">a task repetition by duration expression</param>
/// <param name="organization">the organization that owns this Task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Created Task</returns>
/// <exception cref="NotImplementedException"></exception>
public Task<TaskType> CreateTaskEveryAsync(string name, string flux, string every,
Organization organization, CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(name, nameof(name));
Arguments.CheckNonEmptyString(flux, nameof(flux));
Arguments.CheckNonEmptyString(every, nameof(every));
Arguments.CheckNotNull(organization, nameof(organization));
return CreateTaskEveryAsync(name, flux, every, organization.Id, cancellationToken);
}
/// <summary>
/// Creates a new task with task repetition by duration expression ("1h", "30s"). The <see cref="TaskType.Flux" /> is
/// without a cron or a every repetition.
/// The repetition is automatically append to the <a href="http://bit.ly/option-statement">option statement</a>.
/// </summary>
/// <param name="name">description of the task</param>
/// <param name="flux">the Flux script to run for this task</param>
/// <param name="every">a task repetition by duration expression</param>
/// <param name="orgId">the organization ID that owns this Task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Created Task</returns>
/// <exception cref="NotImplementedException"></exception>
public Task<TaskType> CreateTaskEveryAsync(string name, string flux, string every,
string orgId, CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(name, nameof(name));
Arguments.CheckNonEmptyString(flux, nameof(flux));
Arguments.CheckNonEmptyString(every, nameof(every));
Arguments.CheckNonEmptyString(orgId, nameof(orgId));
var task = CreateTaskAsync(name, flux, every, null, orgId);
return CreateTaskAsync(task, cancellationToken);
}
/// <summary>
/// Update a task. This will cancel all queued runs.
/// </summary>
/// <param name="task">task update to apply</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>task updated</returns>
public Task<TaskType> UpdateTaskAsync(TaskType task, CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(task, nameof(task));
var status = (TaskStatusType)Enum.Parse(typeof(TaskStatusType), task.Status.ToString());
var request = new TaskUpdateRequest(status, task.Flux, task.Name, task.Every, task.Cron);
return UpdateTaskAsync(task.Id, request, cancellationToken);
}
/// <summary>
/// Update a task. This will cancel all queued runs.
/// </summary>
/// <param name="taskId">ID of task to get</param>
/// <param name="request">task update to apply</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>task updated</returns>
public Task<TaskType> UpdateTaskAsync(string taskId, TaskUpdateRequest request,
CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(taskId, nameof(taskId));
Arguments.CheckNotNull(request, nameof(request));
return _service.PatchTasksIDAsync(taskId, request, cancellationToken: cancellationToken);
}
/// <summary>
/// Delete a task.
/// </summary>
/// <param name="taskId">ID of task to delete</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>task deleted</returns>
public Task DeleteTaskAsync(string taskId, CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(taskId, nameof(taskId));
return _service.DeleteTasksIDAsync(taskId, cancellationToken: cancellationToken);
}
/// <summary>
/// Delete a task.
/// </summary>
/// <param name="task">task to delete</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>task deleted</returns>
public Task DeleteTaskAsync(TaskType task, CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(task, nameof(task));
return DeleteTaskAsync(task.Id, cancellationToken);
}
/// <summary>
/// Clone a task.
/// </summary>
/// <param name="taskId">ID of task to clone</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>cloned task</returns>
public async Task<TaskType> CloneTaskAsync(string taskId, CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(taskId, nameof(taskId));
var task = await FindTaskByIdAsync(taskId, cancellationToken).ConfigureAwait(false);
return await CloneTaskAsync(task, cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// Clone a task.
/// </summary>
/// <param name="task">task to clone</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>cloned task</returns>
public async Task<TaskType> CloneTaskAsync(TaskType task, CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(task, nameof(task));
var status = (TaskStatusType)Enum.Parse(typeof(TaskStatusType), task.Status.ToString());
var cloned = new TaskCreateRequest(task.OrgID, task.Org, status,
task.Flux, task.Description);
var created = await CreateTaskAsync(cloned, cancellationToken).ConfigureAwait(false);
var labels = await GetLabelsAsync(task, cancellationToken).ConfigureAwait(false);
foreach (var label in labels) await AddLabelAsync(label, created, cancellationToken).ConfigureAwait(false);
return created;
}
/// <summary>
/// Retrieve a task.
/// </summary>
/// <param name="taskId">ID of task to get</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>task details</returns>
public Task<TaskType> FindTaskByIdAsync(string taskId, CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(taskId, nameof(taskId));
return _service.GetTasksIDAsync(taskId, cancellationToken: cancellationToken);
}
/// <summary>
/// Lists tasks, limit 100.
/// </summary>
/// <param name="user">filter tasks to a specific user</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>A list of tasks</returns>
public Task<List<TaskType>> FindTasksByUserAsync(User user, CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(user, nameof(user));
return FindTasksByUserIdAsync(user.Id, cancellationToken);
}
/// <summary>
/// Lists tasks, limit 100.
/// </summary>
/// <param name="userId">filter tasks to a specific user ID</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>A list of tasks</returns>
public Task<List<TaskType>> FindTasksByUserIdAsync(string userId, CancellationToken cancellationToken = default)
{
return FindTasksAsync(userId: userId, cancellationToken: cancellationToken);
}
/// <summary>
/// Lists tasks, limit 100.
/// </summary>
/// <param name="organization">filter tasks to a specific organization</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>A list of tasks</returns>
public Task<List<TaskType>> FindTasksByOrganizationAsync(Organization organization,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(organization, nameof(organization));
return FindTasksByOrganizationIdAsync(organization.Id, cancellationToken);
}
/// <summary>
/// Lists tasks, limit 100.
/// </summary>
/// <param name="orgId">filter tasks to a specific organization ID</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>A list of tasks</returns>
public Task<List<TaskType>> FindTasksByOrganizationIdAsync(string orgId,
CancellationToken cancellationToken = default)
{
return FindTasksAsync(orgId: orgId, cancellationToken: cancellationToken);
}
/// <summary>
/// Lists tasks, limit 100.
/// </summary>
/// <param name="afterId">returns tasks after specified ID</param>
/// <param name="userId">filter tasks to a specific user ID</param>
/// <param name="orgId">filter tasks to a specific organization ID</param>
/// <param name="org">Filter tasks to a specific organization name. (optional)</param>
/// <param name="name">Returns task with a specific name. (optional)</param>
/// <param name="limit">The number of tasks to return (optional, default to 100)</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>A list of tasks</returns>
public async Task<List<TaskType>> FindTasksAsync(string afterId = null, string userId = null,
string orgId = null, string org = null, string name = null, int? limit = null,
CancellationToken cancellationToken = default)
{
var response = await _service
.GetTasksAsync(after: afterId, user: userId, orgID: orgId, name: name, org: org, limit: limit,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
return response._Tasks;
}
/// <summary>
/// List all members of a task.
/// </summary>
/// <param name="task">task of the members</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the List all members of a task</returns>
public Task<List<ResourceMember>> GetMembersAsync(TaskType task, CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(task, "task");
return GetMembersAsync(task.Id, cancellationToken);
}
/// <summary>
/// List all members of a task.
/// </summary>
/// <param name="taskId">ID of task to get members</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the List all members of a task</returns>
public async Task<List<ResourceMember>> GetMembersAsync(string taskId,
CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(taskId, nameof(taskId));
var response = await _service.GetTasksIDMembersAsync(taskId, cancellationToken: cancellationToken)
.ConfigureAwait(false);
return response.Users;
}
/// <summary>
/// Add a task member.
/// </summary>
/// <param name="member">the member of a task</param>
/// <param name="task">the task of a member</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>created mapping</returns>
public Task<ResourceMember> AddMemberAsync(User member, TaskType task,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(task, "task");
Arguments.CheckNotNull(member, "member");
return AddMemberAsync(member.Id, task.Id, cancellationToken);
}
/// <summary>
/// Add a task member.
/// </summary>
/// <param name="memberId">the ID of a member</param>
/// <param name="taskId">the ID of a task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>created mapping</returns>
public Task<ResourceMember> AddMemberAsync(string memberId, string taskId,
CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(taskId, nameof(taskId));
Arguments.CheckNonEmptyString(memberId, nameof(memberId));
return _service.PostTasksIDMembersAsync(taskId, new AddResourceMemberRequestBody(memberId),
cancellationToken: cancellationToken);
}
/// <summary>
/// Removes a member from a task.
/// </summary>
/// <param name="member">the member of a task</param>
/// <param name="task">the task of a member</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>member removed</returns>
public Task DeleteMemberAsync(User member, TaskType task, CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(task, "task");
Arguments.CheckNotNull(member, "member");
return DeleteMemberAsync(member.Id, task.Id, cancellationToken);
}
/// <summary>
/// Removes a member from a task.
/// </summary>
/// <param name="memberId">the ID of a member</param>
/// <param name="taskId">the ID of a task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>member removed</returns>
public Task DeleteMemberAsync(string memberId, string taskId, CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(taskId, nameof(taskId));
Arguments.CheckNonEmptyString(memberId, nameof(memberId));
return _service.DeleteTasksIDMembersIDAsync(memberId, taskId, cancellationToken: cancellationToken);
}
/// <summary>
/// List all owners of a task.
/// </summary>
/// <param name="task">task of the owners</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the List all owners of a task</returns>
public Task<List<ResourceOwner>> GetOwnersAsync(TaskType task, CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(task, "Task is required");
return GetOwnersAsync(task.Id, cancellationToken);
}
/// <summary>
/// List all owners of a task.
/// </summary>
/// <param name="taskId">ID of a task to get owners</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>the List all owners of a task</returns>
public async Task<List<ResourceOwner>> GetOwnersAsync(string taskId,
CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(taskId, nameof(taskId));
var response = await _service.GetTasksIDOwnersAsync(taskId, cancellationToken: cancellationToken)
.ConfigureAwait(false);
return response.Users;
}
/// <summary>
/// Add a task owner.
/// </summary>
/// <param name="owner">the owner of a task</param>
/// <param name="task">the task of a owner</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>created mapping</returns>
public Task<ResourceOwner> AddOwnerAsync(User owner, TaskType task,
CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(task, "task");
Arguments.CheckNotNull(owner, "owner");
return AddOwnerAsync(owner.Id, task.Id, cancellationToken);
}
/// <summary>
/// Add a task owner.
/// </summary>
/// <param name="ownerId">the ID of a owner</param>
/// <param name="taskId">the ID of a task</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>created mapping</returns>
public Task<ResourceOwner> AddOwnerAsync(string ownerId, string taskId,
CancellationToken cancellationToken = default)
{
Arguments.CheckNonEmptyString(taskId, nameof(taskId));
Arguments.CheckNonEmptyString(ownerId, nameof(ownerId));
return _service.PostTasksIDOwnersAsync(taskId, new AddResourceMemberRequestBody(ownerId),
cancellationToken: cancellationToken);
}
/// <summary>
/// Removes a owner from a task.
/// </summary>
/// <param name="owner">the owner of a task</param>
/// <param name="task">the task of a owner</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>owner removed</returns>
public Task DeleteOwnerAsync(User owner, TaskType task, CancellationToken cancellationToken = default)
{
Arguments.CheckNotNull(task, "task");
Arguments.CheckNotNull(owner, "owner");
return DeleteOwnerAsync(owner.Id, task.Id, cancellationToken);
}