github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/api/ui/debug/js/archive.js (about) 1 // Copyright (c) 2017-2018 Uber Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 function initSchedulerViewer() { 16 // Disable null value warning from data table. 17 $.fn.dataTable.ext.errMode = 'none'; 18 19 $.ajax({ 20 url: "/dbg/jobs/archiving", 21 success: function (body) { 22 var runningJobData = [] 23 var pastRunsData = [] 24 for (var key in body) { 25 var strs = key.split("|") 26 var row = body[key] 27 row['table'] = strs[0] 28 row['shard'] = strs[1] 29 row['type'] = strs[2] 30 if ('lastDuration' in row) { 31 row['lastDuration'] = row['lastDuration'].toDuration() 32 } 33 if (row['status'] == 'running') { 34 runningJobData.push(row) 35 } else { 36 pastRunsData.push(row) 37 } 38 } 39 initRunningJobTable(runningJobData) 40 initPastRunTable(pastRunsData) 41 }, 42 error: function (xhr) { 43 alert(xhr.responseText) 44 } 45 } 46 ) 47 } 48 49 function openArchiveDialog(table, shard) { 50 var timePicker = $('#time-picker') 51 if (timePicker) { 52 timePicker.datetimepicker('destroy') 53 } 54 timePicker.datetimepicker() 55 $('#archiving-dialog').dialog() 56 var url = "/dbg/{0}/{1}/archive".format(table, shard) 57 $('#submit').on("click", function () { 58 var cutoff = $("#cutoff").val() 59 // if cutoff is empty , read from date picker. 60 if (!cutoff) { 61 var timePickerVal = $('#time-picker').val() 62 if (!timePickerVal) { 63 alert("Please input cutoff!") 64 return 65 } 66 var dt = new Date(timePickerVal) 67 // Get seconds. 68 cutoff = dt.getTime() / 1000 69 console.log(cutoff) 70 } 71 72 $.ajax({ 73 url: url, 74 method: "POST", 75 data: JSON.stringify({cutoff: parseInt(cutoff)}), 76 dataType: 'json', 77 success: function (body) { 78 alert(body); 79 reloadCurrentTab(); 80 }, 81 error: function (xhr) { 82 alert(xhr.responseText); 83 } 84 } 85 ) 86 }) 87 } 88 89 function initRunningJobTable(data) { 90 $('#running-job-table').DataTable({ 91 paging: false, 92 searching: false, 93 aoColumns: [ 94 {title: "Table", data: "table"}, 95 {title: "Shard", data: "shard", type: "num"}, 96 {title: "Type", data: "type"}, 97 { 98 title: "Running Cutoff", 99 data: "runningCutoff", 100 render: function (data) { 101 return data + " " + new Date(data * 1000).toLocaleString() 102 } 103 }, 104 {title: "Stage", data: "stage"}, 105 {title: "Current", data: "current", type: "num"}, 106 {title: "Total", data: "total", type: "num"}, 107 ], 108 aaData: data, 109 }); 110 } 111 112 function initPastRunTable(data) { 113 $('#past-runs-table').DataTable({ 114 paging: true, 115 searching: true, 116 pageLength: 20, 117 lengthMenu: [[1, 10, 25, 50, 100], [1, 10, 25, 50, 100]], 118 aoColumns: [ 119 {title: "Table", data: "table"}, 120 {title: "Shard", data: "shard", type: "num"}, 121 {title: "Type", data: "type"}, 122 { 123 title: "Current Cutoff", 124 data: "currentCutoff", 125 render: function (data) { 126 return data + " " + new Date(data * 1000).toLocaleString() 127 } 128 }, 129 {title: "Status", data: "status"}, 130 { 131 title: "Next Run", 132 data: "nextRun", 133 type: "date", 134 render: function (data) { 135 return new Date(data).toLocaleString() 136 } 137 }, 138 {title: "Number of Records Archived", data: "numRecords", type: "num"}, 139 {title: "Number of Affected Days", data: "numAffectedDays", type: "num"}, 140 { 141 title: "Action", 142 mData: null, 143 bSortable: false, 144 mRender: function (data, type, row) { 145 var table = row['table'] 146 var shard = row['shard'] 147 return $("<div />").append($( 148 "<button class='ui-button' onclick=\"openArchiveDialog('" + table + "'," + shard + ")\">Archive</button>")).html(); 149 }, 150 }, 151 { 152 title: "Last Cutoff", 153 data: "lastCutoff", 154 render: function (data) { 155 return data + " " + new Date(data * 1000).toLocaleString() 156 } 157 }, 158 { 159 title: "Last Error", 160 data: "lastError", 161 type: "string", 162 render: function (data) { 163 return JSON.stringify(data) 164 } 165 }, 166 { 167 title: "Last Start Time", 168 data: "lastStartTime", 169 type: "date", 170 render: function (data) { 171 return new Date(data).toLocaleString() 172 } 173 }, 174 {title: "Last Duration", data: "lastDuration", type: "string"}, 175 ], 176 aaData: data, 177 }); 178 }