Skip to content

CON-72 notify when device is offline #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Arusey
Copy link
Contributor

@Arusey Arusey commented Jun 28, 2019

Description

This Pull request allows an administrator for the converge web app to receive notifications whenever a device has not been seen in a while.

Type of Change

  • New feature (non-breaking change which adds functionality

How can this be tested

  • checkout to the branch and run migrations using make migrate message="migration message"

  • Install dependencies using pip install -r requirements.txt

  • Ensure your database has a number of devices in which their activity is online - their last seen should also be greater than a day relative to the current time

  • Run the following command on a different terminal to startup your scheduler
    celery worker -A cworker.celery --loglevel=info
    celery -A cworker.celery beat -l info

  • create an index.html on your browser using the script attached below and inspect your console.

  <html lang="en">
  <head>
    <title>Flask_Chat_App</title>
    <script
      src="https://code.jquery.com/jquery-3.4.1.min.js"
      integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
      crossorigin="anonymous"></script>
  </head>
  <body>

    <h3 id="#messages" style='color: #ccc;font-size: 30px;'>No message yet..</h3>
    <div class="message_holder"></div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.3/socket.io.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function() {
        var socket = io.connect('http://127.0.0.1:5000');
        socket.on('connect', function() {
          socket.send('User has connected!');
        });
        socket.on('message', function(msg) {
          console.log(msg)
          console.log('Received message');
        });
        socket.on('notification', function(msg) {
          console.log(msg)
          console.log('Received EVENT');
        });
      });
    </script>

  </body>
  </html>```
#### How has this been tested
- [x] Unit tests
- [x] Integration tests

#### Checklist
- [x] My code follows the style guidelines of this project
- [x] I have linted my code prior to submission
- [x] My changes generate no new warnings
- [x] Existing unit tests pass locally with my changes
- [x] Implementation works according to expectations

#### JIRA
[CON-72](https://andela-apprenticeship.atlassian.net/jira/software/projects/CON/boards/15/backlog?label=backend&selectedIssue=CON-72)

@Arusey Arusey added the wip label Jun 28, 2019
@Arusey Arusey force-pushed the story/CON-72-notify-when-device-is-offline branch 11 times, most recently from 460f813 to 84be43d Compare July 1, 2019 15:42
@Arusey Arusey removed the wip label Jul 1, 2019
@Arusey Arusey force-pushed the story/CON-72-notify-when-device-is-offline branch 5 times, most recently from 499fe62 to a454487 Compare July 3, 2019 09:26
@mnswaleh
Copy link
Contributor

mnswaleh commented Jul 5, 2019

Kindly include how to test the PR on the comment

@Arusey Arusey force-pushed the story/CON-72-notify-when-device-is-offline branch 3 times, most recently from cb17143 to 44acb26 Compare July 9, 2019 13:28
Copy link
Contributor

@mnswaleh mnswaleh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice implementation. The notifications are being created

@Arusey Arusey force-pushed the story/CON-72-notify-when-device-is-offline branch 2 times, most recently from 1b2da8b to d67684b Compare July 10, 2019 09:51
@Arusey Arusey force-pushed the story/CON-72-notify-when-device-is-offline branch 4 times, most recently from 0bcf20d to 7f05d61 Compare July 10, 2019 11:56
@Arusey Arusey requested review from cop1fab and rajeman July 11, 2019 12:40
@Arusey Arusey force-pushed the story/CON-72-notify-when-device-is-offline branch 9 times, most recently from 763aff5 to b7b5fad Compare July 16, 2019 08:30
Copy link
Contributor

@rajeman rajeman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Arusey Kindly fix your commit messages. You have more than 1.

@Arusey Arusey force-pushed the story/CON-72-notify-when-device-is-offline branch 2 times, most recently from 4e6154b to e1c0d89 Compare July 16, 2019 12:23
@Arusey
Copy link
Contributor Author

Arusey commented Jul 16, 2019

@Arusey Kindly fix your commit messages. You have more than 1.

Done

@Arusey Arusey force-pushed the story/CON-72-notify-when-device-is-offline branch 2 times, most recently from 218fa32 to fedf9ec Compare July 18, 2019 10:02
- create device is offline notification
- periodically check the device last seen
- add too states for a device: online or offline

[Finishes CON-72]
@Arusey Arusey force-pushed the story/CON-72-notify-when-device-is-offline branch from fedf9ec to 8056793 Compare July 18, 2019 11:22
class AdminNotification(Base, Utility):
__tablename__ = 'admin_notifications'

id = Column(Integer, primary_key=True) # noqa
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need # noqa here as this line of code is pep8 compliant.



class Devices(Base, Utility):
__tablename__ = 'devices'
id = Column(Integer, Sequence('devices_id_seq', start=1, increment=1), primary_key=True) # noqa
id = Column(Integer, Sequence('devices_id_seq', start=1, increment=1), primary_key=True) # noqa
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change on this line is not needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants