Adding in management of time range to lookup automation logs in.

This commit is contained in:
mike12345567 2022-06-24 18:11:19 +01:00
parent 1550e8f0a3
commit 70e5a81db2
3 changed files with 24 additions and 18 deletions

View File

@ -5,6 +5,7 @@
import HistoryDetailsPanel from "./HistoryDetailsPanel.svelte" import HistoryDetailsPanel from "./HistoryDetailsPanel.svelte"
import { automationStore } from "builderStore" import { automationStore } from "builderStore"
import { onMount } from "svelte" import { onMount } from "svelte"
import dayjs from "dayjs"
const ERROR = "error", const ERROR = "error",
SUCCESS = "success" SUCCESS = "success"
@ -23,14 +24,14 @@
hasNextPage, hasNextPage,
pageNumber = 1 pageNumber = 1
$: fetchLogs(automationId, status, page) $: fetchLogs(automationId, status, page, timeRange)
const timeOptions = [ const timeOptions = [
{ value: "1w", label: "Past week" }, { value: "1-w", label: "Past week" },
{ value: "1d", label: "Past day" }, { value: "1-d", label: "Past day" },
{ value: "1h", label: "Past 1 hour" }, { value: "1-h", label: "Past 1 hour" },
{ value: "15m", label: "Past 15 mins" }, { value: "15-m", label: "Past 15 mins" },
{ value: "5m", label: "Past 5 mins" }, { value: "5-m", label: "Past 5 mins" },
] ]
const statusOptions = [ const statusOptions = [
@ -49,11 +50,17 @@
{ column: "status", component: StatusRenderer }, { 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({ const response = await automationStore.actions.getLogs({
automationId, automationId,
status, status,
page, page,
startDate,
}) })
nextPage = response.nextPage nextPage = response.nextPage
hasNextPage = response.hasNextPage hasNextPage = response.hasNextPage

View File

@ -1,6 +1,6 @@
const actions = require("../../automations/actions") const actions = require("../../automations/actions")
const triggers = require("../../automations/triggers") const triggers = require("../../automations/triggers")
const { getLogs, oneDayAgo } = require("../../automations/logging") const { getLogs, oneMonthAgo } = require("../../automations/logging")
const { const {
getAutomationParams, getAutomationParams,
generateAutomationID, generateAutomationID,
@ -194,10 +194,11 @@ exports.destroy = async function (ctx) {
} }
exports.logSearch = async function (ctx) { exports.logSearch = async function (ctx) {
const { automationId, status, page } = ctx.request.body let { automationId, status, page, startDate } = ctx.request.body
// TODO: check if there is a date range in the search params // TODO: need to check maximum allowed in license
// also check the date range vs their license, see if it is allowed if (!startDate) {
const startDate = oneDayAgo() startDate = oneMonthAgo()
}
ctx.body = await getLogs(startDate, status, automationId, page) ctx.body = await getLogs(startDate, status, automationId, page)
} }

View File

@ -22,7 +22,7 @@ import * as env from "../../environment"
const PAGE_SIZE = 9 const PAGE_SIZE = 9
const EARLIEST_DATE = new Date(0).toISOString() const EARLIEST_DATE = new Date(0).toISOString()
const FREE_EXPIRY_SEC = 86400 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) { function getStatus(results: AutomationResults) {
let status = AutomationStatus.SUCCESS let status = AutomationStatus.SUCCESS
@ -40,11 +40,9 @@ function getStatus(results: AutomationResults) {
return status return status
} }
// export function oneMonthAgo() { export function oneMonthAgo() {
// return new Date( return new Date(new Date().getTime() - PRO_EXPIRY_SEC * 1000).toISOString()
// new Date().getTime() - PRO_EXPIRY_SEC * 1000 }
// ).toISOString()
// }
export function oneDayAgo() { export function oneDayAgo() {
return new Date(new Date().getTime() - FREE_EXPIRY_SEC * 1000).toISOString() return new Date(new Date().getTime() - FREE_EXPIRY_SEC * 1000).toISOString()