From 1f6e2d3618de5db4e215760e9edcb46a590d836b Mon Sep 17 00:00:00 2001 From: orangecoding Date: Thu, 13 May 2021 20:27:42 +0200 Subject: [PATCH] adding inforamtion about when the processor ran the last time --- index.js | 1 + lib/api/routes/jobRouter.js | 9 +++++++++ ui/src/App.js | 1 + ui/src/services/rematch/models/jobs.js | 15 +++++++++++++++ ui/src/views/jobs/Jobs.js | 13 +++++++++---- ui/src/views/jobs/ProcessingTimes.js | 26 ++++++++++++++++++++++++++ 6 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 ui/src/views/jobs/ProcessingTimes.js diff --git a/index.js b/index.js index 4670aa4..67f7cdb 100755 --- a/index.js +++ b/index.js @@ -24,6 +24,7 @@ console.log(`Started Fredy successfully. Ui can be accessed via http://localhost /* eslint-enable no-console */ setInterval( (function exec() { + config.lastRun = Date.now(); jobStorage .getJobs() .filter((job) => job.enabled) diff --git a/lib/api/routes/jobRouter.js b/lib/api/routes/jobRouter.js index eebb89a..41ed28e 100644 --- a/lib/api/routes/jobRouter.js +++ b/lib/api/routes/jobRouter.js @@ -29,6 +29,15 @@ jobRouter.get('/', async (req, res) => { res.send(); }); +jobRouter.get('/processingTimes', async (req, res) => { + res.body = { + interval: config.interval, + lastRun: config.lastRun || null, + }; + + res.send(); +}); + jobRouter.post('/', async (req, res) => { const { provider, notificationAdapter, name, blacklist = [], jobId, enabled } = req.body; if ( diff --git a/ui/src/App.js b/ui/src/App.js index eaf4dd7..a755fec 100644 --- a/ui/src/App.js +++ b/ui/src/App.js @@ -29,6 +29,7 @@ export default function FredyApp() { useEffect(async () => { await dispatch.provider.getProvider(); await dispatch.jobs.getJobs(); + await dispatch.jobs.getProcessingTimes(); await dispatch.notificationAdapter.getAdapter(); await dispatch.user.getCurrentUser(); diff --git a/ui/src/services/rematch/models/jobs.js b/ui/src/services/rematch/models/jobs.js index 4eed6a1..0e047ed 100644 --- a/ui/src/services/rematch/models/jobs.js +++ b/ui/src/services/rematch/models/jobs.js @@ -4,6 +4,7 @@ export const jobs = { state: { jobs: [], insights: {}, + processingTimes: {}, }, reducers: { setJobs: (state, payload) => { @@ -12,6 +13,12 @@ export const jobs = { jobs: Object.freeze(payload), }; }, + setProcessingTimes: (state, payload) => { + return { + ...state, + processingTimes: Object.freeze(payload), + }; + }, setJobInsights: (state, payload, jobId) => { return { ...state, @@ -31,6 +38,14 @@ export const jobs = { console.error(`Error while trying to get resource for api/jobs. Error:`, Exception); } }, + async getProcessingTimes() { + try { + const response = await xhrGet('/api/jobs/processingTimes'); + this.setProcessingTimes(response.json); + } catch (Exception) { + console.error(`Error while trying to get resource for api/processingTimes. Error:`, Exception); + } + }, async getInsightDataForJob(jobId) { try { const response = await xhrGet(`/api/jobs/insights/${jobId}`); diff --git a/ui/src/views/jobs/Jobs.js b/ui/src/views/jobs/Jobs.js index 8d9d4df..4347a80 100644 --- a/ui/src/views/jobs/Jobs.js +++ b/ui/src/views/jobs/Jobs.js @@ -6,11 +6,13 @@ import { useSelector, useDispatch } from 'react-redux'; import { xhrDelete, xhrPut } from '../../services/xhr'; import { Button, Icon } from 'semantic-ui-react'; import { useHistory } from 'react-router-dom'; +import ProcessingTimes from './ProcessingTimes'; import './Jobs.less'; export default function Jobs() { const jobs = useSelector((state) => state.jobs.jobs); + const processingTimes = useSelector((state) => state.jobs.processingTimes); const history = useHistory(); const dispatch = useDispatch(); const ctx = React.useContext(ToastContext); @@ -61,10 +63,13 @@ export default function Jobs() { return (
- +
+ {processingTimes != null && } + +
+ + {processingTimes.lastRun && ( + + + + + )} + + ); +}