symphony v0.1.1

Symphony: A Crystal framework for streamlined asynchronous input/output handling with safe shutdown protocols.

Symphony

Simplifies the startup and safe shutdown of Crystal servers that process inputs (such as queues and HTTP requests) and stream them to various outputs. Unlike traditional HTTP servers that directly respond to requests, this framework is designed for asynchronous processing.

The core idea is to let the application define a list of readers (input) and writers (output), where each reader and writer will run independently.

The framework will take care of the proper startup (first the writers, then the readers) and the safe shutdown (stopping first the readers, then the writers). It will also handle signals like SIGINT or SIGTERM.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      symphony:
        github: philipp-classen/symphony
    
  2. Run shards install

Usage

Here is a minimal example to illustrate how to set up a basic server. While this example does not include a writer and may not be practically useful, it demonstrates the basic structure of a Symphony application.

require "symphony"

class Application < Symphony::Application
  Log = ::Log.for("test-app")

  def create_input_readers : Array(Symphony::BackgroundService)
    server = Symphony::HttpServer.new do |ctx|
      ctx.response.content_type = "text/plain"
      ctx.response.print "Hello world, got #{ctx.request.path}!"
    end
    [server] of Symphony::BackgroundService
  end

  def create_output_writers : Array(Symphony::BackgroundService)
    [] of Symphony::BackgroundService
  end
end

Log.setup_from_env
APP = Application.new
APP.run

Development

There are currently no tests.

Contributing

  1. Fork it (https://github.com/philipp-classen/symphony/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

symphony

Owner
Statistic
  • 0
  • 0
  • 1
  • 0
  • 0
  • 5 months ago
  • July 1, 2024
License

MIT License

Links
Synced at

Sun, 22 Dec 2024 06:06:34 GMT

Languages