Adding in management of time range to lookup automation logs in.
This commit is contained in:
parent
b5af76de56
commit
9fd64307a9
|
@ -5,6 +5,7 @@
|
|||
import HistoryDetailsPanel from "./HistoryDetailsPanel.svelte"
|
||||
import { automationStore } from "builderStore"
|
||||
import { onMount } from "svelte"
|
||||
import dayjs from "dayjs"
|
||||
|
||||
const ERROR = "error",
|
||||
SUCCESS = "success"
|
||||
|
@ -23,14 +24,14 @@
|
|||
hasNextPage,
|
||||
pageNumber = 1
|
||||
|
||||
$: fetchLogs(automationId, status, page)
|
||||
$: fetchLogs(automationId, status, page, timeRange)
|
||||
|
||||
const timeOptions = [
|
||||
{ value: "1w", label: "Past week" },
|
||||
{ value: "1d", label: "Past day" },
|
||||
{ value: "1h", label: "Past 1 hour" },
|
||||
{ value: "15m", label: "Past 15 mins" },
|
||||
{ value: "5m", label: "Past 5 mins" },
|
||||
{ value: "1-w", label: "Past week" },
|
||||
{ value: "1-d", label: "Past day" },
|
||||
{ value: "1-h", label: "Past 1 hour" },
|
||||
{ value: "15-m", label: "Past 15 mins" },
|
||||
{ value: "5-m", label: "Past 5 mins" },
|
||||
]
|
||||
|
||||
const statusOptions = [
|
||||
|
@ -49,11 +50,17 @@
|
|||
{ column: "status", component: StatusRenderer },
|
||||
]
|
||||
|
||||
async function fetchLogs(automationId, status, page) {
|
||||
async function fetchLogs(automationId, status, page, timeRange) {
|
||||
let startDate = null
|
||||
if (timeRange) {
|
||||
const [length, units] = timeRange.split("-")
|
||||
startDate = dayjs().subtract(length, units)
|
||||
}
|
||||
const response = await automationStore.actions.getLogs({
|
||||
automationId,
|
||||
status,
|
||||
page,
|
||||
startDate,
|
||||
})
|
||||
nextPage = response.nextPage
|
||||
hasNextPage = response.hasNextPage
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const actions = require("../../automations/actions")
|
||||
const triggers = require("../../automations/triggers")
|
||||
const { getLogs, oneDayAgo } = require("../../automations/logging")
|
||||
const { getLogs, oneMonthAgo } = require("../../automations/logging")
|
||||
const {
|
||||
getAutomationParams,
|
||||
generateAutomationID,
|
||||
|
@ -194,10 +194,11 @@ exports.destroy = async function (ctx) {
|
|||
}
|
||||
|
||||
exports.logSearch = async function (ctx) {
|
||||
const { automationId, status, page } = ctx.request.body
|
||||
// TODO: check if there is a date range in the search params
|
||||
// also check the date range vs their license, see if it is allowed
|
||||
const startDate = oneDayAgo()
|
||||
let { automationId, status, page, startDate } = ctx.request.body
|
||||
// TODO: need to check maximum allowed in license
|
||||
if (!startDate) {
|
||||
startDate = oneMonthAgo()
|
||||
}
|
||||
ctx.body = await getLogs(startDate, status, automationId, page)
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import * as env from "../../environment"
|
|||
const PAGE_SIZE = 9
|
||||
const EARLIEST_DATE = new Date(0).toISOString()
|
||||
const FREE_EXPIRY_SEC = 86400
|
||||
// const PRO_EXPIRY_SEC = FREE_EXPIRY_SEC * 30
|
||||
const PRO_EXPIRY_SEC = FREE_EXPIRY_SEC * 30
|
||||
|
||||
function getStatus(results: AutomationResults) {
|
||||
let status = AutomationStatus.SUCCESS
|
||||
|
@ -40,11 +40,9 @@ function getStatus(results: AutomationResults) {
|
|||
return status
|
||||
}
|
||||
|
||||
// export function oneMonthAgo() {
|
||||
// return new Date(
|
||||
// new Date().getTime() - PRO_EXPIRY_SEC * 1000
|
||||
// ).toISOString()
|
||||
// }
|
||||
export function oneMonthAgo() {
|
||||
return new Date(new Date().getTime() - PRO_EXPIRY_SEC * 1000).toISOString()
|
||||
}
|
||||
|
||||
export function oneDayAgo() {
|
||||
return new Date(new Date().getTime() - FREE_EXPIRY_SEC * 1000).toISOString()
|
||||
|
|
Loading…
Reference in New Issue