github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/ui/src/api.ts (about) 1 import axios from "axios"; 2 import queryString from "query-string"; 3 4 // In production build, API server is on listening on the same port as 5 // the static file server. 6 // In developement, we assume that the API server is listening on port 8080. 7 const getBaseUrl = () => 8 process.env.NODE_ENV === "production" 9 ? `${window.ROOT_PATH}/api` 10 : `http://localhost:8080${window.ROOT_PATH}/api`; 11 12 export interface ListQueuesResponse { 13 queues: Queue[]; 14 } 15 16 export interface ListTasksResponse { 17 tasks: TaskInfo[]; 18 stats: Queue; 19 } 20 21 export interface ListAggregatingTasksResponse { 22 tasks: TaskInfo[]; 23 stats: Queue; 24 groups: GroupInfo[]; 25 } 26 27 export interface ListServersResponse { 28 servers: ServerInfo[]; 29 } 30 31 export interface ListSchedulerEntriesResponse { 32 entries: SchedulerEntry[]; 33 } 34 35 export interface ListSchedulerEnqueueEventsResponse { 36 events: SchedulerEnqueueEvent[]; 37 } 38 39 export interface BatchCancelTasksResponse { 40 canceled_ids: string[]; 41 error_ids: string[]; 42 } 43 44 export interface BatchDeleteTasksResponse { 45 deleted_ids: string[]; 46 failed_ids: string[]; 47 } 48 49 export interface BatchRunTasksResponse { 50 pending_ids: string[]; 51 error_ids: string[]; 52 } 53 54 export interface BatchArchiveTasksResponse { 55 archived_ids: string[]; 56 error_ids: string[]; 57 } 58 59 export interface DeleteAllTasksResponse { 60 deleted: number; 61 } 62 63 export interface ArchiveAllTasksResponse { 64 archived: number; 65 } 66 67 export interface RunAllTasksResponse { 68 scheduled: number; 69 } 70 71 export interface ListQueueStatsResponse { 72 stats: { [qname: string]: DailyStat[] }; 73 } 74 75 export interface ListGroupsResponse { 76 stats: Queue; 77 groups: GroupInfo[]; 78 } 79 80 export interface RedisInfoResponse { 81 address: string; 82 info: RedisInfo; 83 raw_info: string; 84 cluster: boolean; 85 86 // following fields are set only when cluster=true 87 raw_cluster_nodes: string; 88 queue_locations: QueueLocation[] | null; 89 } 90 91 // Describes location of a queue in cluster. 92 export interface QueueLocation { 93 queue: string; // queue name 94 keyslot: number; // cluster keyslot 95 nodes: string[]; // node addresses 96 } 97 98 export interface MetricsResponse { 99 queue_size: PrometheusMetricsResponse; 100 queue_latency_seconds: PrometheusMetricsResponse; 101 queue_memory_usage_approx_bytes: PrometheusMetricsResponse; 102 tasks_processed_per_second: PrometheusMetricsResponse; 103 tasks_failed_per_second: PrometheusMetricsResponse; 104 error_rate: PrometheusMetricsResponse; 105 pending_tasks_by_queue: PrometheusMetricsResponse; 106 retry_tasks_by_queue: PrometheusMetricsResponse; 107 archived_tasks_by_queue: PrometheusMetricsResponse; 108 } 109 110 export interface PrometheusMetricsResponse { 111 status: "success" | "error"; 112 data?: MetricsResult; // present if status === "success" 113 error?: string; // present if status === "error" 114 errorType?: string; // present if status === "error" 115 } 116 117 export interface MetricsResult { 118 resultType: string; 119 result: Metrics[]; 120 } 121 122 export interface Metrics { 123 metric: MetricsInfo; 124 values: [number, string][]; // [unixtime, value] 125 } 126 127 export interface MetricsInfo { 128 __name__: string; 129 instance: string; 130 job: string; 131 132 // labels (may or may not be present depending on metrics) 133 queue?: string; 134 state?: string; 135 } 136 137 // Return value from redis INFO command. 138 // See https://redis.io/commands/info#return-value. 139 export interface RedisInfo { 140 active_defrag_hits: string; 141 active_defrag_key_hits: string; 142 active_defrag_key_misses: string; 143 active_defrag_misses: string; 144 active_defrag_running: string; 145 allocator_active: string; 146 allocator_allocated: string; 147 allocator_frag_bytes: string; 148 allocator_frag_ratio: string; 149 allocator_resident: string; 150 allocator_rss_bytes: string; 151 allocator_rss_ratio: string; 152 aof_current_rewrite_time_sec: string; 153 aof_enabled: string; 154 aof_last_bgrewrite_status: string; 155 aof_last_cow_size: string; 156 aof_last_rewrite_time_sec: string; 157 aof_last_write_status: string; 158 aof_rewrite_in_progress: string; 159 aof_rewrite_scheduled: string; 160 arch_bits: string; 161 atomicvar_api: string; 162 blocked_clients: string; 163 client_recent_max_input_buffer: string; 164 client_recent_max_output_buffer: string; 165 clients_in_timeout_table: string; 166 cluster_enabled: string; 167 config_file: string; 168 configured_hz: string; 169 connected_clients: string; 170 connected_slaves: string; 171 evicted_keys: string; 172 executable: string; 173 expire_cycle_cpu_milliseconds: string; 174 expired_keys: string; 175 expired_stale_perc: string; 176 expired_time_cap_reached_count: string; 177 gcc_version: string; 178 hz: string; 179 instantaneous_input_kbps: string; 180 instantaneous_ops_per_sec: string; 181 instantaneous_output_kbps: string; 182 keyspace_hits: string; 183 keyspace_misses: string; 184 latest_fork_usec: string; 185 lazyfree_pending_objects: string; 186 loading: string; 187 lru_clock: string; 188 master_repl_offset: string; 189 master_replid: string; 190 master_replid2: string; 191 maxmemory: string; 192 maxmemory_human: string; 193 maxmemory_policy: string; 194 mem_allocator: string; 195 mem_aof_buffer: string; 196 mem_clients_normal: string; 197 mem_clients_slaves: string; 198 mem_fragmentation_bytes: string; 199 mem_fragmentation_ratio: string; 200 mem_not_counted_for_evict: string; 201 mem_replication_backlog: string; 202 migrate_cached_sockets: string; 203 module_fork_in_progress: string; 204 module_fork_last_cow_size: string; 205 multiplexing_api: string; 206 number_of_cached_scripts: string; 207 os: string; 208 process_id: string; 209 pubsub_channels: string; 210 pubsub_patterns: string; 211 rdb_bgsave_in_progress: string; 212 rdb_changes_since_last_save: string; 213 rdb_current_bgsave_time_sec: string; 214 rdb_last_bgsave_status: string; 215 rdb_last_bgsave_time_sec: string; 216 rdb_last_cow_size: string; 217 rdb_last_save_time: string; 218 redis_build_id: string; 219 redis_git_dirty: string; 220 redis_git_sha1: string; 221 redis_mode: string; 222 redis_version: string; 223 rejected_connections: string; 224 repl_backlog_active: string; 225 repl_backlog_first_byte_offset: string; 226 repl_backlog_histlen: string; 227 repl_backlog_size: string; 228 role: string; 229 rss_overhead_bytes: string; 230 rss_overhead_ratio: string; 231 run_id: string; 232 second_repl_offset: string; 233 slave_expires_tracked_keys: string; 234 sync_full: string; 235 sync_partial_err: string; 236 sync_partial_ok: string; 237 tcp_port: string; 238 total_commands_processed: string; 239 total_connections_received: string; 240 total_net_input_bytes: string; 241 total_net_output_bytes: string; 242 total_system_memory: string; 243 total_system_memory_human: string; 244 tracking_clients: string; 245 tracking_total_items: string; 246 tracking_total_keys: string; 247 tracking_total_prefixes: string; 248 unexpected_error_replies: string; 249 uptime_in_days: string; 250 uptime_in_seconds: string; 251 used_cpu_sys: string; 252 used_cpu_sys_children: string; 253 used_cpu_user: string; 254 used_cpu_user_children: string; 255 used_memory: string; 256 used_memory_dataset: string; 257 used_memory_dataset_perc: string; 258 used_memory_human: string; 259 used_memory_lua: string; 260 used_memory_lua_human: string; 261 used_memory_overhead: string; 262 used_memory_peak: string; 263 used_memory_peak_human: string; 264 used_memory_peak_perc: string; 265 used_memory_rss: string; 266 used_memory_rss_human: string; 267 used_memory_scripts: string; 268 used_memory_scripts_human: string; 269 used_memory_startup: string; 270 } 271 272 export interface GroupInfo { 273 group: string; 274 size: number; 275 } 276 277 export interface Queue { 278 queue: string; 279 paused: boolean; 280 size: number; 281 groups: number; 282 latency_msec: number; 283 display_latency: string; 284 memory_usage_bytes: number; 285 active: number; 286 pending: number; 287 aggregating: number; 288 scheduled: number; 289 retry: number; 290 archived: number; 291 completed: number; 292 processed: number; 293 failed: number; 294 timestamp: string; 295 } 296 297 export interface DailyStat { 298 queue: string; 299 date: string; 300 processed: number; 301 failed: number; 302 } 303 304 export interface TaskInfo { 305 id: string; 306 queue: string; 307 type: string; 308 payload: string; 309 state: string; 310 start_time: string; // Only applies to task.state == 'active' 311 max_retry: number; 312 retried: number; 313 last_failed_at: string; 314 error_message: string; 315 next_process_at: string; 316 timeout_seconds: number; 317 deadline: string; 318 group: string; 319 completed_at: string; 320 result: string; 321 ttl_seconds: number; 322 is_orphaned: boolean; // Only applies to task.state == 'active' 323 } 324 325 export interface ServerInfo { 326 id: string; 327 host: string; 328 pid: number; 329 concurrency: number; 330 queue_priorities: { [qname: string]: number }; 331 strict_priority_enabled: boolean; 332 start_time: string; 333 status: string; 334 active_workers: WorkerInfo[]; 335 } 336 337 export interface WorkerInfo { 338 task_id: string; 339 queue: string; 340 task_type: string; 341 task_payload: string; 342 start_time: string; 343 } 344 345 export interface SchedulerEntry { 346 id: string; 347 spec: string; 348 task_type: string; 349 task_payload: string; 350 options: string[]; 351 next_enqueue_at: string; 352 // prev_enqueue_at will be omitted 353 // if there were no previous enqueue events. 354 prev_enqueue_at?: string; 355 } 356 357 export interface SchedulerEnqueueEvent { 358 task_id: string; 359 enqueued_at: string; 360 } 361 362 export interface PaginationOptions extends Record<string, number | undefined> { 363 size?: number; // size of the page 364 page?: number; // page number (1 being the first page) 365 } 366 367 export async function listQueues(): Promise<ListQueuesResponse> { 368 const resp = await axios({ 369 method: "get", 370 url: `${getBaseUrl()}/queues`, 371 }); 372 return resp.data; 373 } 374 375 export async function deleteQueue(qname: string): Promise<void> { 376 await axios({ 377 method: "delete", 378 url: `${getBaseUrl()}/queues/${qname}`, 379 }); 380 } 381 382 export async function pauseQueue(qname: string): Promise<void> { 383 await axios({ 384 method: "post", 385 url: `${getBaseUrl()}/queues/${qname}:pause`, 386 }); 387 } 388 389 export async function resumeQueue(qname: string): Promise<void> { 390 await axios({ 391 method: "post", 392 url: `${getBaseUrl()}/queues/${qname}:resume`, 393 }); 394 } 395 396 export async function listQueueStats(): Promise<ListQueueStatsResponse> { 397 const resp = await axios({ 398 method: "get", 399 url: `${getBaseUrl()}/queue_stats`, 400 }); 401 return resp.data; 402 } 403 404 export async function listGroups(qname: string): Promise<ListGroupsResponse> { 405 const resp = await axios({ 406 method: "get", 407 url: `${getBaseUrl()}/queues/${qname}/groups`, 408 }); 409 return resp.data; 410 } 411 412 export async function getTaskInfo( 413 qname: string, 414 id: string 415 ): Promise<TaskInfo> { 416 const url = `${getBaseUrl()}/queues/${qname}/tasks/${id}`; 417 const resp = await axios({ 418 method: "get", 419 url, 420 }); 421 return resp.data; 422 } 423 424 export async function listActiveTasks( 425 qname: string, 426 pageOpts?: PaginationOptions 427 ): Promise<ListTasksResponse> { 428 let url = `${getBaseUrl()}/queues/${qname}/active_tasks`; 429 if (pageOpts) { 430 url += `?${queryString.stringify(pageOpts)}`; 431 } 432 const resp = await axios({ 433 method: "get", 434 url, 435 }); 436 return resp.data; 437 } 438 439 export async function cancelActiveTask( 440 qname: string, 441 taskId: string 442 ): Promise<void> { 443 await axios({ 444 method: "post", 445 url: `${getBaseUrl()}/queues/${qname}/active_tasks/${taskId}:cancel`, 446 }); 447 } 448 449 export async function cancelAllActiveTasks(qname: string): Promise<void> { 450 await axios({ 451 method: "post", 452 url: `${getBaseUrl()}/queues/${qname}/active_tasks:cancel_all`, 453 }); 454 } 455 456 export async function batchCancelActiveTasks( 457 qname: string, 458 taskIds: string[] 459 ): Promise<BatchCancelTasksResponse> { 460 const resp = await axios({ 461 method: "post", 462 url: `${getBaseUrl()}/queues/${qname}/active_tasks:batch_cancel`, 463 data: { 464 task_ids: taskIds, 465 }, 466 }); 467 return resp.data; 468 } 469 470 export async function listPendingTasks( 471 qname: string, 472 pageOpts?: PaginationOptions 473 ): Promise<ListTasksResponse> { 474 let url = `${getBaseUrl()}/queues/${qname}/pending_tasks`; 475 if (pageOpts) { 476 url += `?${queryString.stringify(pageOpts)}`; 477 } 478 const resp = await axios({ 479 method: "get", 480 url, 481 }); 482 return resp.data; 483 } 484 485 export async function listScheduledTasks( 486 qname: string, 487 pageOpts?: PaginationOptions 488 ): Promise<ListTasksResponse> { 489 let url = `${getBaseUrl()}/queues/${qname}/scheduled_tasks`; 490 if (pageOpts) { 491 url += `?${queryString.stringify(pageOpts)}`; 492 } 493 const resp = await axios({ 494 method: "get", 495 url, 496 }); 497 return resp.data; 498 } 499 500 export async function listRetryTasks( 501 qname: string, 502 pageOpts?: PaginationOptions 503 ): Promise<ListTasksResponse> { 504 let url = `${getBaseUrl()}/queues/${qname}/retry_tasks`; 505 if (pageOpts) { 506 url += `?${queryString.stringify(pageOpts)}`; 507 } 508 const resp = await axios({ 509 method: "get", 510 url, 511 }); 512 return resp.data; 513 } 514 515 export async function listArchivedTasks( 516 qname: string, 517 pageOpts?: PaginationOptions 518 ): Promise<ListTasksResponse> { 519 let url = `${getBaseUrl()}/queues/${qname}/archived_tasks`; 520 if (pageOpts) { 521 url += `?${queryString.stringify(pageOpts)}`; 522 } 523 const resp = await axios({ 524 method: "get", 525 url, 526 }); 527 return resp.data; 528 } 529 530 export async function listCompletedTasks( 531 qname: string, 532 pageOpts?: PaginationOptions 533 ): Promise<ListTasksResponse> { 534 let url = `${getBaseUrl()}/queues/${qname}/completed_tasks`; 535 if (pageOpts) { 536 url += `?${queryString.stringify(pageOpts)}`; 537 } 538 const resp = await axios({ 539 method: "get", 540 url, 541 }); 542 return resp.data; 543 } 544 545 export async function listAggregatingTasks( 546 qname: string, 547 gname: string, 548 pageOpts?: PaginationOptions 549 ): Promise<ListAggregatingTasksResponse> { 550 let url = `${getBaseUrl()}/queues/${qname}/groups/${gname}/aggregating_tasks`; 551 if (pageOpts) { 552 url += `?${queryString.stringify(pageOpts)}`; 553 } 554 const resp = await axios({ 555 method: "get", 556 url, 557 }); 558 return resp.data; 559 } 560 561 export async function archivePendingTask( 562 qname: string, 563 taskId: string 564 ): Promise<void> { 565 await axios({ 566 method: "post", 567 url: `${getBaseUrl()}/queues/${qname}/pending_tasks/${taskId}:archive`, 568 }); 569 } 570 571 export async function batchArchivePendingTasks( 572 qname: string, 573 taskIds: string[] 574 ): Promise<BatchArchiveTasksResponse> { 575 const resp = await axios({ 576 method: "post", 577 url: `${getBaseUrl()}/queues/${qname}/pending_tasks:batch_archive`, 578 data: { 579 task_ids: taskIds, 580 }, 581 }); 582 return resp.data; 583 } 584 585 export async function archiveAllPendingTasks(qname: string): Promise<void> { 586 await axios({ 587 method: "post", 588 url: `${getBaseUrl()}/queues/${qname}/pending_tasks:archive_all`, 589 }); 590 } 591 592 export async function deletePendingTask( 593 qname: string, 594 taskId: string 595 ): Promise<void> { 596 await axios({ 597 method: "delete", 598 url: `${getBaseUrl()}/queues/${qname}/pending_tasks/${taskId}`, 599 }); 600 } 601 602 export async function batchDeletePendingTasks( 603 qname: string, 604 taskIds: string[] 605 ): Promise<BatchDeleteTasksResponse> { 606 const resp = await axios({ 607 method: "post", 608 url: `${getBaseUrl()}/queues/${qname}/pending_tasks:batch_delete`, 609 data: { 610 task_ids: taskIds, 611 }, 612 }); 613 return resp.data; 614 } 615 616 export async function deleteAllPendingTasks( 617 qname: string 618 ): Promise<DeleteAllTasksResponse> { 619 const resp = await axios({ 620 method: "delete", 621 url: `${getBaseUrl()}/queues/${qname}/pending_tasks:delete_all`, 622 }); 623 return resp.data; 624 } 625 626 export async function deleteAggregatingTask( 627 qname: string, 628 gname: string, 629 taskId: string 630 ): Promise<void> { 631 await axios({ 632 method: "delete", 633 url: `${getBaseUrl()}/queues/${qname}/groups/${gname}/aggregating_tasks/${taskId}`, 634 }); 635 } 636 637 export async function batchDeleteAggregatingTasks( 638 qname: string, 639 gname: string, 640 taskIds: string[] 641 ): Promise<BatchDeleteTasksResponse> { 642 const resp = await axios({ 643 method: "post", 644 url: `${getBaseUrl()}/queues/${qname}/groups/${gname}/aggregating_tasks:batch_delete`, 645 data: { 646 task_ids: taskIds, 647 }, 648 }); 649 return resp.data; 650 } 651 652 export async function deleteAllAggregatingTasks( 653 qname: string, 654 gname: string 655 ): Promise<DeleteAllTasksResponse> { 656 const resp = await axios({ 657 method: "delete", 658 url: `${getBaseUrl()}/queues/${qname}/groups/${gname}/aggregating_tasks:delete_all`, 659 }); 660 return resp.data; 661 } 662 663 export async function runAggregatingTask( 664 qname: string, 665 gname: string, 666 taskId: string 667 ): Promise<void> { 668 await axios({ 669 method: "post", 670 url: `${getBaseUrl()}/queues/${qname}/groups/${gname}/aggregating_tasks/${taskId}:run`, 671 }); 672 } 673 674 export async function batchRunAggregatingTasks( 675 qname: string, 676 gname: string, 677 taskIds: string[] 678 ): Promise<BatchRunTasksResponse> { 679 const resp = await axios({ 680 method: "post", 681 url: `${getBaseUrl()}/queues/${qname}/groups/${gname}/aggregating_tasks:batch_run`, 682 data: { 683 task_ids: taskIds, 684 }, 685 }); 686 return resp.data; 687 } 688 689 export async function runAllAggregatingTasks( 690 qname: string, 691 gname: string 692 ): Promise<RunAllTasksResponse> { 693 const resp = await axios({ 694 method: "post", 695 url: `${getBaseUrl()}/queues/${qname}/groups/${gname}/aggregating_tasks:run_all`, 696 }); 697 return resp.data; 698 } 699 700 export async function archiveAggregatingTask( 701 qname: string, 702 gname: string, 703 taskId: string 704 ): Promise<void> { 705 await axios({ 706 method: "post", 707 url: `${getBaseUrl()}/queues/${qname}/groups/${gname}/aggregating_tasks/${taskId}:archive`, 708 }); 709 } 710 711 export async function batchArchiveAggregatingTasks( 712 qname: string, 713 gname: string, 714 taskIds: string[] 715 ): Promise<BatchArchiveTasksResponse> { 716 const resp = await axios({ 717 method: "post", 718 url: `${getBaseUrl()}/queues/${qname}/groups/${gname}/aggregating_tasks:batch_archive`, 719 data: { 720 task_ids: taskIds, 721 }, 722 }); 723 return resp.data; 724 } 725 726 export async function archiveAllAggregatingTasks( 727 qname: string, 728 gname: string 729 ): Promise<ArchiveAllTasksResponse> { 730 const resp = await axios({ 731 method: "post", 732 url: `${getBaseUrl()}/queues/${qname}/groups/${gname}/aggregating_tasks:archive_all`, 733 }); 734 return resp.data; 735 } 736 737 export async function runScheduledTask( 738 qname: string, 739 taskId: string 740 ): Promise<void> { 741 await axios({ 742 method: "post", 743 url: `${getBaseUrl()}/queues/${qname}/scheduled_tasks/${taskId}:run`, 744 }); 745 } 746 747 export async function archiveScheduledTask( 748 qname: string, 749 taskId: string 750 ): Promise<void> { 751 await axios({ 752 method: "post", 753 url: `${getBaseUrl()}/queues/${qname}/scheduled_tasks/${taskId}:archive`, 754 }); 755 } 756 757 export async function deleteScheduledTask( 758 qname: string, 759 taskId: string 760 ): Promise<void> { 761 await axios({ 762 method: "delete", 763 url: `${getBaseUrl()}/queues/${qname}/scheduled_tasks/${taskId}`, 764 }); 765 } 766 767 export async function batchDeleteScheduledTasks( 768 qname: string, 769 taskIds: string[] 770 ): Promise<BatchDeleteTasksResponse> { 771 const resp = await axios({ 772 method: "post", 773 url: `${getBaseUrl()}/queues/${qname}/scheduled_tasks:batch_delete`, 774 data: { 775 task_ids: taskIds, 776 }, 777 }); 778 return resp.data; 779 } 780 781 export async function deleteAllScheduledTasks( 782 qname: string 783 ): Promise<DeleteAllTasksResponse> { 784 const resp = await axios({ 785 method: "delete", 786 url: `${getBaseUrl()}/queues/${qname}/scheduled_tasks:delete_all`, 787 }); 788 return resp.data; 789 } 790 791 export async function batchRunScheduledTasks( 792 qname: string, 793 taskIds: string[] 794 ): Promise<BatchRunTasksResponse> { 795 const resp = await axios({ 796 method: "post", 797 url: `${getBaseUrl()}/queues/${qname}/scheduled_tasks:batch_run`, 798 data: { 799 task_ids: taskIds, 800 }, 801 }); 802 return resp.data; 803 } 804 805 export async function runAllScheduledTasks(qname: string): Promise<void> { 806 await axios({ 807 method: "post", 808 url: `${getBaseUrl()}/queues/${qname}/scheduled_tasks:run_all`, 809 }); 810 } 811 812 export async function batchArchiveScheduledTasks( 813 qname: string, 814 taskIds: string[] 815 ): Promise<BatchArchiveTasksResponse> { 816 const resp = await axios({ 817 method: "post", 818 url: `${getBaseUrl()}/queues/${qname}/scheduled_tasks:batch_archive`, 819 data: { 820 task_ids: taskIds, 821 }, 822 }); 823 return resp.data; 824 } 825 826 export async function archiveAllScheduledTasks(qname: string): Promise<void> { 827 await axios({ 828 method: "post", 829 url: `${getBaseUrl()}/queues/${qname}/scheduled_tasks:archive_all`, 830 }); 831 } 832 833 export async function runRetryTask( 834 qname: string, 835 taskId: string 836 ): Promise<void> { 837 await axios({ 838 method: "post", 839 url: `${getBaseUrl()}/queues/${qname}/retry_tasks/${taskId}:run`, 840 }); 841 } 842 843 export async function archiveRetryTask( 844 qname: string, 845 taskId: string 846 ): Promise<void> { 847 await axios({ 848 method: "post", 849 url: `${getBaseUrl()}/queues/${qname}/retry_tasks/${taskId}:archive`, 850 }); 851 } 852 853 export async function deleteRetryTask( 854 qname: string, 855 taskId: string 856 ): Promise<void> { 857 await axios({ 858 method: "delete", 859 url: `${getBaseUrl()}/queues/${qname}/retry_tasks/${taskId}`, 860 }); 861 } 862 863 export async function batchDeleteRetryTasks( 864 qname: string, 865 taskIds: string[] 866 ): Promise<BatchDeleteTasksResponse> { 867 const resp = await axios({ 868 method: "post", 869 url: `${getBaseUrl()}/queues/${qname}/retry_tasks:batch_delete`, 870 data: { 871 task_ids: taskIds, 872 }, 873 }); 874 return resp.data; 875 } 876 877 export async function deleteAllRetryTasks( 878 qname: string 879 ): Promise<DeleteAllTasksResponse> { 880 const resp = await axios({ 881 method: "delete", 882 url: `${getBaseUrl()}/queues/${qname}/retry_tasks:delete_all`, 883 }); 884 return resp.data; 885 } 886 887 export async function batchRunRetryTasks( 888 qname: string, 889 taskIds: string[] 890 ): Promise<BatchRunTasksResponse> { 891 const resp = await axios({ 892 method: "post", 893 url: `${getBaseUrl()}/queues/${qname}/retry_tasks:batch_run`, 894 data: { 895 task_ids: taskIds, 896 }, 897 }); 898 return resp.data; 899 } 900 901 export async function runAllRetryTasks(qname: string): Promise<void> { 902 await axios({ 903 method: "post", 904 url: `${getBaseUrl()}/queues/${qname}/retry_tasks:run_all`, 905 }); 906 } 907 908 export async function batchArchiveRetryTasks( 909 qname: string, 910 taskIds: string[] 911 ): Promise<BatchArchiveTasksResponse> { 912 const resp = await axios({ 913 method: "post", 914 url: `${getBaseUrl()}/queues/${qname}/retry_tasks:batch_archive`, 915 data: { 916 task_ids: taskIds, 917 }, 918 }); 919 return resp.data; 920 } 921 922 export async function archiveAllRetryTasks(qname: string): Promise<void> { 923 await axios({ 924 method: "post", 925 url: `${getBaseUrl()}/queues/${qname}/retry_tasks:archive_all`, 926 }); 927 } 928 929 export async function runArchivedTask( 930 qname: string, 931 taskId: string 932 ): Promise<void> { 933 await axios({ 934 method: "post", 935 url: `${getBaseUrl()}/queues/${qname}/archived_tasks/${taskId}:run`, 936 }); 937 } 938 939 export async function deleteArchivedTask( 940 qname: string, 941 taskId: string 942 ): Promise<void> { 943 await axios({ 944 method: "delete", 945 url: `${getBaseUrl()}/queues/${qname}/archived_tasks/${taskId}`, 946 }); 947 } 948 949 export async function batchDeleteArchivedTasks( 950 qname: string, 951 taskIds: string[] 952 ): Promise<BatchDeleteTasksResponse> { 953 const resp = await axios({ 954 method: "post", 955 url: `${getBaseUrl()}/queues/${qname}/archived_tasks:batch_delete`, 956 data: { 957 task_ids: taskIds, 958 }, 959 }); 960 return resp.data; 961 } 962 963 export async function deleteAllArchivedTasks( 964 qname: string 965 ): Promise<DeleteAllTasksResponse> { 966 const resp = await axios({ 967 method: "delete", 968 url: `${getBaseUrl()}/queues/${qname}/archived_tasks:delete_all`, 969 }); 970 return resp.data; 971 } 972 973 export async function batchRunArchivedTasks( 974 qname: string, 975 taskIds: string[] 976 ): Promise<BatchRunTasksResponse> { 977 const resp = await axios({ 978 method: "post", 979 url: `${getBaseUrl()}/queues/${qname}/archived_tasks:batch_run`, 980 data: { 981 task_ids: taskIds, 982 }, 983 }); 984 return resp.data; 985 } 986 987 export async function runAllArchivedTasks(qname: string): Promise<void> { 988 await axios({ 989 method: "post", 990 url: `${getBaseUrl()}/queues/${qname}/archived_tasks:run_all`, 991 }); 992 } 993 994 export async function deleteCompletedTask( 995 qname: string, 996 taskId: string 997 ): Promise<void> { 998 await axios({ 999 method: "delete", 1000 url: `${getBaseUrl()}/queues/${qname}/completed_tasks/${taskId}`, 1001 }); 1002 } 1003 1004 export async function batchDeleteCompletedTasks( 1005 qname: string, 1006 taskIds: string[] 1007 ): Promise<BatchDeleteTasksResponse> { 1008 const resp = await axios({ 1009 method: "post", 1010 url: `${getBaseUrl()}/queues/${qname}/completed_tasks:batch_delete`, 1011 data: { 1012 task_ids: taskIds, 1013 }, 1014 }); 1015 return resp.data; 1016 } 1017 1018 export async function deleteAllCompletedTasks( 1019 qname: string 1020 ): Promise<DeleteAllTasksResponse> { 1021 const resp = await axios({ 1022 method: "delete", 1023 url: `${getBaseUrl()}/queues/${qname}/completed_tasks:delete_all`, 1024 }); 1025 return resp.data; 1026 } 1027 1028 export async function listServers(): Promise<ListServersResponse> { 1029 const resp = await axios({ 1030 method: "get", 1031 url: `${getBaseUrl()}/servers`, 1032 }); 1033 return resp.data; 1034 } 1035 1036 export async function listSchedulerEntries(): Promise<ListSchedulerEntriesResponse> { 1037 const resp = await axios({ 1038 method: "get", 1039 url: `${getBaseUrl()}/scheduler_entries`, 1040 }); 1041 return resp.data; 1042 } 1043 1044 export async function listSchedulerEnqueueEvents( 1045 entryId: string 1046 ): Promise<ListSchedulerEnqueueEventsResponse> { 1047 const resp = await axios({ 1048 method: "get", 1049 url: `${getBaseUrl()}/scheduler_entries/${entryId}/enqueue_events`, 1050 }); 1051 return resp.data; 1052 } 1053 1054 export async function getRedisInfo(): Promise<RedisInfoResponse> { 1055 const resp = await axios({ 1056 method: "get", 1057 url: `${getBaseUrl()}/redis_info`, 1058 }); 1059 return resp.data; 1060 } 1061 1062 interface MetricsEndpointParams { 1063 endtime: number; 1064 duration: number; 1065 queues?: string; // comma-separated list of queues 1066 } 1067 1068 export async function getMetrics( 1069 endTime: number, 1070 duration: number, 1071 queues: string[] 1072 ): Promise<MetricsResponse> { 1073 let params: MetricsEndpointParams = { 1074 endtime: endTime, 1075 duration: duration, 1076 }; 1077 if (queues && queues.length > 0) { 1078 params.queues = queues.join(","); 1079 } 1080 const resp = await axios({ 1081 method: "get", 1082 url: `${getBaseUrl()}/metrics?${queryString.stringify(params)}`, 1083 }); 1084 return resp.data; 1085 }