GithubHelp home page GithubHelp logo

go-notifier's Introduction

Notifier

Considerations

To meet the requirements of the test I have made the following decisions:

  • Using the concurrency pipelines pattern, which in this case is composed by two stages connected by channels, which will allow concurrent processing (reading and sending) of STDIN messages.
  • Using a buffered channel in order to continue reading(not block the channel) the messages from the STDIN in case of the time interval for sending the messages is very high.
  • Creating an independent channel to store the errors of each stage and based on the information from this Google blog, merge the two channels, this allows it to monitor the result of the pipeline execution and control if I want to terminate the process (canceling the context) when one or more errors are found.
  • The number of errors allowed can be configured using the environment variable NOTIFIER_MAXALLOWEDERRORS.
  • Sharing the context with the gracefullyShutdown function to listen for the SIGINT signal and gracefully terminate the process by canceling the context.

Other aspects of the design of the solution:

  • Use of dependency inversion creating an interface for the HTTP client and passing it to the processor together with the file io.Reader interface for reading the STDIN.
  • The logs are categorized by level, it is possible to select the logging level of the service with the LogLevel environment variable.
  • It is possible to configure different aspects of the application through environment variables.
  • Unit tests are included.
  • Including Make as interface to execute commands to compile, test, check(linter) the program.
  • Docker configuration.

Environment Variables

  • NOTIFIER_INTERVAL: Allows to set a default interval for sending notifications.
  • NOTIFIER_MAXALLOWEDERRORS:The application will terminate when it has reached this number of errors
  • NOTIFIER_LOGLEVEL:Log level
  • NOTIFIER_BUFFERSIZE:Buffer size for the message channel.
  • NOTIFIER_HTTPREQUESTTIMEOUT:Configuring the timeout time for the http client.
  • NOTIFIER_MAXIDLECONNS: controls the maximum number of idle(keep-alive) connections across all hosts.
  • NOTIFIER_MAXIDLECONNSPERHOST: restricts how many connections there are which are not actively serving requests.

Execute the program

  • Locally
make compile
./bin/notifier -u http://localhost:8080/notify < messages.txt -i 10ms
  • Docker
make make compile
docker build -t notifier .
docker run -i notifier -u http://localhost:8080/notify < messages.txt -i 200ms

Run tests

make test

Run checks

make check

go-notifier's People

Contributors

wvalencia19 avatar

Watchers

 avatar

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.