Skip to content

Commit

Permalink
add delay when failed uploading, send to different mqtt topic when no…
Browse files Browse the repository at this point in the history
… hub + fixes responsiveness
  • Loading branch information
cedricve committed Mar 23, 2023
1 parent 71cd315 commit f935360
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 29 deletions.
9 changes: 9 additions & 0 deletions machinery/src/cloud/Cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func HandleUpload(configuration *models.Configuration, communication *models.Com
log.Log.Debug("HandleUpload: stopping as Offline is enabled.")
} else {

// Half a second delay between two uploads
delay := 500 * time.Millisecond

loop:
for {
// This will check if we need to stop the thread,
Expand All @@ -69,6 +72,7 @@ func HandleUpload(configuration *models.Configuration, communication *models.Com
log.Log.Error("HandleUpload: " + err.Error())
} else {
for _, f := range ff {

// This will check if we need to stop the thread,
// because of a reconfiguration.
select {
Expand All @@ -89,6 +93,7 @@ func HandleUpload(configuration *models.Configuration, communication *models.Com

// Check if the file is uploaded, if so, remove it.
if uploaded {
delay = 500 * time.Millisecond // reset
err := os.Remove(watchDirectory + fileName)
if err != nil {
log.Log.Error("HandleUpload: " + err.Error())
Expand All @@ -107,8 +112,12 @@ func HandleUpload(configuration *models.Configuration, communication *models.Com
if err != nil {
log.Log.Error("HandleUpload: " + err.Error())
}
} else {
delay = 5 * time.Second // slow down
log.Log.Error("HandleUpload: " + err.Error())
}

time.Sleep(delay)
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions machinery/src/computervision/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,12 @@ func ProcessMotion(motionCursor *pubsub.QueueCursor, configuration *models.Confi

// If offline mode is disabled, send a message to the hub
if config.Offline == "false" {
if mqttClient != nil && key != "" {
mqttClient.Publish("kerberos/"+key+"/device/"+config.Key+"/motion", 2, false, "motion")
if mqttClient != nil {
if key != "" {
mqttClient.Publish("kerberos/"+key+"/device/"+config.Key+"/motion", 2, false, "motion")
} else {
mqttClient.Publish("kerberos/device/"+config.Key+"/motion", 2, false, "motion")
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": false,
"dependencies": {
"@giantmachines/redux-websocket": "^1.5.1",
"@kerberos-io/ui": "^1.71.0",
"@kerberos-io/ui": "^1.72.0",
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@testing-library/jest-dom": "^5.16.5",
Expand Down
11 changes: 11 additions & 0 deletions ui/src/App.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
@import "./app.variables";

.grid-container {
row-gap: size(2);
}

.main {
padding-top: size(7);

@media (min-width: 800px) {
padding-top: 0;
}
}

.offline-mode, .cloud-not-installed {
background: var(--upper-gradient);
Expand Down
8 changes: 0 additions & 8 deletions ui/src/api/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,3 @@ export function doCheckIfInstalled(onSuccess, onError) {
}
});
}

/* export function doAuth(onSuccess, onError) {
}
export function doRefreshToken(onSuccess, onError) {
} */
11 changes: 9 additions & 2 deletions ui/src/pages/Dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,21 @@ class Dashboard extends React.Component {
id="cells1"
bodycells={[
<>
<div className="time">
<div
className="time"
onClick={() =>
this.openModal(
`${config.URL}/file/${event.key}`
)
}
>
<Ellipse status="success" />{' '}
<p data-tip="10m and 5s ago">{event.time}</p>
</div>
</>,
<>
<p
className="pointer"
className="pointer event-description"
onClick={() =>
this.openModal(
`${config.URL}/file/${event.key}`
Expand Down
9 changes: 9 additions & 0 deletions ui/src/pages/Dashboard/Dashboard.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "../../app.variables";

#dashboard {

hr {
Expand All @@ -15,6 +17,13 @@
video {
width: 100%;
}

p.event-description {
display: none;
@media (min-width: 800px) {
display: block;
}
}

a {
display: flex;
Expand Down
17 changes: 2 additions & 15 deletions ui/src/pages/Media/Media.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
import {
Breadcrumb,
VideoContainer,
VideoCard,
ControlBar,
Button,
Input,
Modal,
ModalHeader,
ModalBody,
Expand Down Expand Up @@ -105,17 +102,7 @@ class Media extends React.Component {
</Link>
</Breadcrumb>

<ControlBar>
<Input
iconleft="search"
onChange={() => {}}
placeholder={t('recordings.search_media')}
layout="controlbar"
type="text"
/>
</ControlBar>

<VideoContainer cols={4} isVideoWall={false}>
<div className="stats grid-container --four-columns">
{events.map((event) => (
<div
key={event.key}
Expand All @@ -135,7 +122,7 @@ class Media extends React.Component {
/>
</div>
))}
</VideoContainer>
</div>
{open && (
<Modal>
<ModalHeader
Expand Down
1 change: 0 additions & 1 deletion ui/src/pages/Settings/Settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
}
}


.table-container table {
border-spacing: 0 12px;
width: 100%;
Expand Down

0 comments on commit f935360

Please sign in to comment.