Giter Site home page Giter Site logo

gnaponie / estuary-updater Goto Github PK

View Code? Open in Web Editor NEW

This project forked from redhat-exd-rebuilds/estuary-updater

0.0 1.0 0.0 172 KB

A micro-service that updates the Neo4j database for Estuary in real-time

License: GNU General Public License v3.0

Dockerfile 2.36% Shell 2.08% Python 95.56%

estuary-updater's Introduction

Docs Status

Getting Started

Overview

Estuary Updater is a micro-service that updates the Neo4j graph database used by Estuary in real-time by reading and processing messages from the UMB.

Run the Unit Tests

Since the unit tests require a running Neo4j instance, the tests are run in Docker containers using Docker Compose. The commands required to run the unit tests are abstracted in scripts/run-tests.sh. This script will create the Docker image required to run the tests based on docker/Dockerfile-tests, create a container with Neo4j, create another container to run the tests based on the built Docker image, run the tests, and then delete the two created containers.

To install Docker and Docker Compose on Fedora, run:

$ sudo dnf install docker docker-compose

To start Docker, run:

$ sudo systemctl start docker

To run the tests, run:

$ sudo scripts/run-tests.sh

To run just a single test, you can run:

sudo scripts/run-tests.sh pytest -vvv tests/test_file::test_name

Code Styling

The codebase conforms to the style enforced by flake8 with the following exceptions:

  • The maximum line length allowed is 100 characters instead of 80 characters

In addition to flake8, docstrings are also enforced by the plugin flake8-docstrings with the following exemptions:

  • D100: Missing docstring in public module
  • D104: Missing docstring in public package

The format of the docstrings should be in the Sphynx style such as:

Get a node from Neo4j.

:param str resource: a resource name that maps to a neomodel class
:param str uid: the value of the UniqueIdProperty to query with
:return: an object representing the Neo4j node
:rtype: neomodel.StructuredNode
:raises ValidationError: if an invalid resource was requested

Creating a New Handler

  • Create a new file in estuary_updater/handlers such as estuary_updater/handlers/distgit.py.
  • At the top of the new file, add the following license header and imports:
    # SPDX-License-Identifier: GPL-3.0+
    
    from __future__ import unicode_literals, absolute_import
    
    from estuary_updater.handlers.base import BaseHandler
  • Then you can proceed to create your handler in the same file as such:
    class DistGitHandler(BaseHandler):
    """A handler for dist-git related messages."""
    
    @staticmethod
    def can_handle(msg):
        """
        Determine if this handler can handle this message.
    
        :param dict msg: a message to be analyzed
        :return: a bool based on if the handler can handle this kind of message
        :rtype: bool
        """
        # Code goes here to determine if the message can be handled by this handler
    
    def handle(self, msg):
        """
        Handle a message and update Neo4j if necessary.
    
        :param dict msg: a message to be processed
        """
        # Code goes here to handle/process the message
  • Then register your handler by adding the class to estuary_updater.handlers.all_handlers such as:
    from estuary_updater.handlers.distgit import DistGitHandler
    
    all_handlers = [DistGitHandler, OtherHandlerHere]
  • Lastly, add any additional topics to the fedmsg.d/config.py file by editing the estuary_updater.topics value.

Writing a New Unit Test For Your Handler

  • Create a new file to store the JSON message you want to test your handler with. This should be stored in tests/messages such as tests/messages/distgit/new_commit.json.
  • Create a new file in tests/handlers/ such as tests/handlers/distgit.py.
  • At the top of the new file, add the following license header and imports:
    # SPDX-License-Identifier: GPL-3.0+
    
    from __future__ import unicode_literals, absolute_import
    
    import json
    from os import path
  • Then you can proceed to create your unit test in the same file as such:
    from estuary.models.distgit import DistGitCommit
    
    from tests import message_dir
    from estuary_updater.handlers.distgit import DistGitHandler
    from estuary_updater import config
    
    
    def test_distgit_new_commit():
        """Test the dist-git handler when it recieves a new commit message."""
        # Load the message to pass to the handler
        with open(path.join(message_dir, 'distgit', 'new_commit.json'), 'r') as f:
            msg = json.load(f)
        # Make sure the handler can handle the message
        assert DistGitHandler.can_handle(msg) is True
        # Instantiate the handler
        handler = DistGitHandler(config)
        # Run the handler
        handler.handle(msg)
        # Verify everything looks good in Neo4j
        commit = DistGitCommit.nodes.get_or_none(hash_='some_hash_from_the_message')
        assert commit is not None
        # Do additional checks here

Code Documentation

To document new files, please check here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.