README
This commit is contained in:
parent
7b6ccda237
commit
e0f0386170
4 changed files with 60 additions and 5 deletions
2
CHANGELOG.md
Normal file
2
CHANGELOG.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# 1.0.0-alpha
|
||||
* Initial version.
|
51
README.md
Normal file
51
README.md
Normal file
|
@ -0,0 +1,51 @@
|
|||
# production
|
||||
Helpers for concurrency, message-passing, rotating loggers, and other production functionality in Angel.
|
||||
|
||||
This will become the de-facto way to run Angel applications in deployed environments, as it
|
||||
takes care of inter-isolate communication, respawning dead processes, and other housekeeping for you automatically.
|
||||
|
||||
Most users will want to use the `Runner` class.
|
||||
|
||||
## `Runner`
|
||||
`Runner` is a utility, powered by `package:args`, that is intended to be the entry point of your application.
|
||||
|
||||
Instantiate it as follows, and your file will become a command-line executable that spawns multiple instances of your
|
||||
application:
|
||||
|
||||
```dart
|
||||
import 'dart:async';
|
||||
import 'dart:isolate';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_production/angel_production.dart';
|
||||
|
||||
main(List<String> args) => new Runner('example', configureServer).run(args);
|
||||
|
||||
Future configureServer(Angel app) async {
|
||||
app.get('/', (req, res) => 'Hello, production world!');
|
||||
|
||||
app.get('/crash', (req, res) {
|
||||
// We'll crash this instance deliberately, but the Runner will auto-respawn for us.
|
||||
new Timer(const Duration(seconds: 3), Isolate.current.kill);
|
||||
return 'Crashing in 3s...';
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
`Runner` will automatically re-spawn crashed instances, unless `--no-respawn` is passed. This can prevent
|
||||
your server from entirely going down at the first error, and adds a layer of fault tolerance to your
|
||||
infrastructure.
|
||||
|
||||
When combined with `systemd`, deploying Angel applications on Linux can be very simple.
|
||||
|
||||
## Message Passing
|
||||
The `Runner` class uses [`package:pub_sub`](https://github.com/thosakwe/pub_sub) to coordinate
|
||||
message passing between isolates.
|
||||
|
||||
When one isolate sends a message, all other isolates will
|
||||
receive the same message, except for the isolate that sent it.
|
||||
|
||||
It is injected into your application's `Container` as
|
||||
`pub_sub.Client`, so you can use it as follows:
|
||||
|
||||
```dart
|
||||
```
|
|
@ -3,10 +3,7 @@ import 'dart:isolate';
|
|||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_production/angel_production.dart';
|
||||
|
||||
main(List<String> args) {
|
||||
var runner = new Runner('example', configureServer);
|
||||
return runner.run(args);
|
||||
}
|
||||
main(List<String> args) => new Runner('example', configureServer).run(args);
|
||||
|
||||
Future configureServer(Angel app) async {
|
||||
app.get('/', (req, res) => 'Hello, production world!');
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
name: angel_production
|
||||
version: 1.0.0-alpha
|
||||
description: Helpers for concurrency, message-passing, rotating loggers, and other production functionality in Angel.
|
||||
homepage: https://github.com/angel-dart/production
|
||||
environment:
|
||||
sdk: ">=2.0.0-dev <3.0.0"
|
||||
dependencies:
|
||||
angel_framework: ^2.0.0-alpha
|
||||
args: ^1.0.0
|
||||
io: ^0.3.2
|
||||
logging: ^0.11.3
|
||||
logging: ^0.11.3
|
||||
|
|
Loading…
Reference in a new issue