Skip to content

Commit 84be43d

Browse files
author
[Arusey]
committed
CON-72-story(notifications): admin receives notification when device is not seen in a while
- setup queue manager for when notifications are sent - implement notifications when device is not seen in a while [Delivers CON-72]
1 parent 1c0e9ff commit 84be43d

File tree

9 files changed

+32
-58
lines changed

9 files changed

+32
-58
lines changed

.circleci/config.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ gcloud_setup: &gcloud_setup
3636
run:
3737
name: setup gcloud
3838
command: |
39-
# install
39+
# install
4040
sudo curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz > /tmp/google-cloud-sdk.tar.gz
41-
sudo mkdir -p /usr/local/gcloud
41+
sudo mkdir -p /usr/local/gcloud
4242
sudo tar -C /usr/local/gcloud -xvf /tmp/google-cloud-sdk.tar.gz
4343
sudo /usr/local/gcloud/google-cloud-sdk/install.sh --quiet
4444
echo PATH=$PATH:/usr/local/gcloud/google-cloud-sdk/bin >> ~/.bashrc
@@ -190,8 +190,8 @@ jobs:
190190
command: |
191191
./cc-test-reporter before-build
192192
. venv/bin/activate
193-
coverage combine parallel-coverage/
194-
coverage xml
193+
coverage combine parallel-coverage/
194+
coverage xml -i
195195
coverage report
196196
./cc-test-reporter format-coverage -o ./.coverage -t coverage.py
197197
./cc-test-reporter upload-coverage -i .coverage
@@ -301,13 +301,13 @@ jobs:
301301
command: |
302302
if [ "$CIRCLE_BRANCH" == master ] || [ "$CIRCLE_BRANCH" == develop ]; then
303303
touch google-service-key.json
304-
echo $GOOGLE_CREDENTIALS_STAGING | base64 --decode >> google-service-key.json
304+
echo $GOOGLE_CREDENTIALS_STAGING | base64 --decode >> google-service-key.json
305305
gcloud auth activate-service-account --key-file google-service-key.json
306306
gcloud --quiet config set project ${GOOGLE_PROJECT_ID_STAGING}
307307
gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}
308308
else
309309
touch google-service-key.json
310-
echo $GOOGLE_CREDENTIALS_SANDBOX | base64 --decode >> google-service-key.json
310+
echo $GOOGLE_CREDENTIALS_SANDBOX | base64 --decode >> google-service-key.json
311311
gcloud auth activate-service-account --key-file google-service-key.json
312312
gcloud --quiet config set project ${GOOGLE_PROJECT_ID_SANDBOX}
313313
gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}

admin_notifications/helpers/create_notification.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
from flask_socketio import send, emit
21
from admin_notifications.models import AdminNotification
32
from manage import socketio
4-
import celery
53

64

7-
@celery.task(name="create-notification")
85
def create_notification(title, message, location_id):
96
notification = AdminNotification(
107
title=title,

admin_notifications/helpers/device_last_seen.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
@celery.task(name='check-device-last-seen')
10-
def notify_when_device_is_offline(**kwargs):
10+
def notify_when_device_is_offline():
1111
query = DevicesModel.query
1212
online_devices = query.filter(DevicesModel.activity == "online").all()
1313
for device in online_devices:
@@ -18,19 +18,13 @@ def notify_when_device_is_offline(**kwargs):
1818
if duration_offline.days > 1:
1919
update_entity_fields(device, activity="offline")
2020
device.save()
21-
return online_devices
22-
2321

24-
@celery.task(name='notify')
25-
def notify():
26-
query = DevicesModel.query
27-
offline_device = query.filter(DevicesModel.activity == "offline").all()
28-
for device in offline_device:
29-
if device:
3022
room_name = device.room.name
3123
room_id = device.room.id
3224
notification_payload = device_offline_notification(
3325
room_name, room_id)
3426
create_notification(title=notification_payload['title'],
3527
message=notification_payload['message'],
3628
location_id=device.room.location_id)
29+
30+
return online_devices
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
def event_auto_cancelled_notification(event_name, room_name):
1+
def device_offline_notification(room_name, room_id):
22
return {
3-
"title": "Event Auto cancelled.",
4-
"message": f"An event {event_name} in {room_name} \
5-
has been auto cancelled."
6-
}
3+
"title": "Device is offline",
4+
"message": f"A device in {room_name} roomid:{room_id} is offline."}

alembic/versions/1b53553ddacf_add_activity_column_to_devices_table.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Flask-JSON==0.3.2
99
Flask-Script==2.0.6
1010
Flask-GraphQL==1.4.1
1111
Flask-Mail==0.9.1
12+
Flask-SocketIO==4.1.0
1213
google-api-python-client==1.6.7
1314
graphene-sqlalchemy==2.0.0
1415
graphene==2.1

tests/test_admin_notification/__init__.py

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from tests.base import BaseTestCase
2+
from unittest.mock import patch, MagicMock
3+
from fixtures.token.token_fixture import ADMIN_TOKEN
4+
from fixtures.devices.devices_fixtures import devices_query
5+
from admin_notifications.helpers.device_last_seen import (
6+
notify_when_device_is_offline)
7+
8+
9+
class TestDeviceOffline(BaseTestCase):
10+
@patch('admin_notifications.helpers.create_notification.socketio.emit',
11+
MagicMock(return_value=True))
12+
def test_when_device_is_offline(self):
13+
"""
14+
Testing for device creation
15+
"""
16+
headers = {"Authorization": "Bearer" + " " + ADMIN_TOKEN}
17+
self.app_test.post(devices_query, headers=headers)
18+
res = notify_when_device_is_offline()
19+
assert res[0].activity.value == 'offline'

utilities/utility.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class QuestionType(enum.Enum):
8989
missingitem = "missing_items"
9090

9191

92-
9392
class StatusType(enum.Enum):
9493
read = "read"
9594
unread = "unread"

0 commit comments

Comments
 (0)