Updated production

This commit is contained in:
thomashii 2021-07-18 13:36:33 +08:00
parent f2eb12551c
commit 9da4eeeb46
6 changed files with 79 additions and 48 deletions

View file

@ -1,18 +1,32 @@
# 3.0.1 # Change Log
## 3.0.2
* Fixed NNBD issues
* Updated references to `angel3` framework
* Updated README
## 3.0.1
* Fixed static analysis warnings * Fixed static analysis warnings
# 3.0.0 ## 3.0.0
* Migrated to support Dart SDK 2.12.x NNBD * Migrated to support Dart SDK 2.12.x NNBD
# 2.0.0 ## 2.0.0
* Migrated to work with Dart SDK 2.12.x Non NNBD * Migrated to work with Dart SDK 2.12.x Non NNBD
# 1.0.0 ## 1.0.0
* Support SSL/HTTP2. * Support SSL/HTTP2.
* Support muting the logger via `--quiet`. * Support muting the logger via `--quiet`.
# 1.0.0-alpha.1 ## 1.0.0-alpha.1
* Import `framework/http`. * Import `framework/http`.
# 1.0.0-alpha ## 1.0.0-alpha
* Initial version. * Initial version.

View file

@ -1,24 +1,24 @@
# angel3_production # Angel3 Production Runner
[![version](https://img.shields.io/badge/pub-v3.0.1-brightgreen)](https://pub.dartlang.org/packages/angel3_production)
[![version](https://img.shields.io/badge/pub-v3.0.2-brightgreen)](https://pub.dartlang.org/packages/angel3_production)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) [![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion) [![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/production/LICENSE) [![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/production/LICENSE)
Helpers for concurrency, message-passing, rotating loggers, and other production functionality in Angel. Helpers for concurrency, message-passing, rotating loggers, and other production functionality in Angel3 framework.
![Screenshot](screenshot.png) ![Screenshot](angel3-screenshot.png)
This will become the de-facto way to run Angel applications in deployed environments, as it This will become the de-facto way to run Angel3 applications in deployed environments, as it takes care of inter-isolate communication, respawning dead processes, and other housekeeping for you automatically.
takes care of inter-isolate communication, respawning dead processes, and other housekeeping for you automatically.
Most users will want to use the `Runner` class. Most users will want to use the `Runner` class.
## `Runner` ## `Runner`
`Runner` is a utility, powered by `package:args`, that is intended to be the entry point of your application. `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 Instantiate it as follows, and your file will become a command-line executable that spawns multiple instances of your application:
application:
```dart ```dart
import 'dart:async'; import 'dart:async';
@ -39,21 +39,18 @@ Future configureServer(Angel app) async {
} }
``` ```
`Runner` will automatically re-spawn crashed instances, unless `--no-respawn` is passed. This can prevent `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.
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. When combined with `systemd`, deploying Angel3 applications on Linux can be very simple.
## Message Passing ## Message Passing
The `Runner` class uses [`package:angel3_pub_sub`](https://github.com/dukefirehawk/angel/tree/angel3/packages/pub_sub) to coordinate The `Runner` class uses [`package:angel3_pub_sub`](https://github.com/dukefirehawk/angel/tree/angel3/packages/pub_sub) to coordinate
message passing between isolates. message passing between isolates.
When one isolate sends a message, all other isolates will When one isolate sends a message, all other isolates will receive the same message, except for the isolate that sent it.
receive the same message, except for the isolate that sent it.
It is injected into your application's `Container` as It is injected into your application's `Container` as `pub_sub.Client`, so you can use it as follows:
`pub_sub.Client`, so you can use it as follows:
```dart ```dart
// Use the injected `pub_sub.Client` to send messages. // Use the injected `pub_sub.Client` to send messages.
@ -71,9 +68,8 @@ onGreetingChanged
``` ```
## Run-time Metadata ## Run-time Metadata
At run-time, you may want to know information about the currently-running instance,
for example, which number instance. For this, the `InstanceInfo` class is injected At run-time, you may want to know information about the currently-running instance, for example, which number instance. For this, the `InstanceInfo` class is injected into each instance:
into each instance:
```dart ```dart
var instanceInfo = app.container.make<InstanceInfo>(); var instanceInfo = app.container.make<InstanceInfo>();
@ -81,19 +77,20 @@ print('This is instance #${instanceInfo.id}');
``` ```
## Command-line Options ## Command-line Options
The `Runner` class supplies options like the following: The `Runner` class supplies options like the following:
``` ```bash
Prod-MacBook-Air:production appuser$ dart example/main.dart --help appuser$ dart example/main.dart --help
____________ ________________________ _ _ _ ____ _____ _ _____
___ |__ | / /_ ____/__ ____/__ / / \ | \ | |/ ___| ____| | |___ /
__ /| |_ |/ /_ / __ __ __/ __ / / _ \ | \| | | _| _| | | |_ \
_ ___ | /| / / /_/ / _ /___ _ /___ / ___ \| |\ | |_| | |___| |___ ___) |
/_/ |_/_/ |_/ ____/ /_____/ /_____/ /_/ \_\_| \_|\____|_____|_____|____/
A batteries-included, full-featured, full-stack framework in Dart. A batteries-included, full-featured, full-stack framework in Dart.
https://angel-dart.github.io https://angel3-framework.web.app
Options: Options:
-h, --help Print this help information. -h, --help Print this help information.

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View file

@ -8,15 +8,15 @@ void main(List<String> args) => Runner('example', configureServer).run(args);
Future configureServer(Angel app) async { Future configureServer(Angel app) async {
// Use the injected `pub_sub.Client` to send messages. // Use the injected `pub_sub.Client` to send messages.
var client = app.container!.make<pub_sub.Client>()!; var client = app.container?.make<pub_sub.Client>();
String? greeting = 'Hello! This is the default greeting.'; var greeting = 'Hello! This is the default greeting.';
// We can listen for an event to perform some behavior. // We can listen for an event to perform some behavior.
// //
// Here, we use message passing to synchronize some common state. // Here, we use message passing to synchronize some common state.
var onGreetingChanged = await client.subscribe('greeting_changed'); var onGreetingChanged = await client?.subscribe('greeting_changed');
onGreetingChanged onGreetingChanged
.cast<String>() ?.cast<String>()
.listen((newGreeting) => greeting = newGreeting); .listen((newGreeting) => greeting = newGreeting);
// Add some routes... // Add some routes...
@ -32,8 +32,8 @@ Future configureServer(Angel app) async {
// This route will push a new value for `greeting`. // This route will push a new value for `greeting`.
app.get('/change_greeting/:newGreeting', (req, res) { app.get('/change_greeting/:newGreeting', (req, res) {
greeting = req.params['newGreeting'] as String?; greeting = (req.params['newGreeting'] as String? ?? '');
client.publish('greeting_changed', greeting); client?.publish('greeting_changed', greeting);
return 'Changed greeting -> $greeting'; return 'Changed greeting -> $greeting';
}); });

View file

@ -26,7 +26,26 @@ class Runner {
Runner(this.name, this.configureServer, Runner(this.name, this.configureServer,
{this.reflector = const EmptyReflector()}); {this.reflector = const EmptyReflector()});
static const String asciiArt2 = '''
___ _ ________________ _____
/ | / | / / ____/ ____/ / |__ /
/ /| | / |/ / / __/ __/ / / /_ <
/ ___ |/ /| / /_/ / /___/ /______/ /
/_/ |_/_/ |_/\\____/_____/_____/____/
''';
static const String asciiArt = ''' static const String asciiArt = '''
_ _ _ ____ _____ _ _____
/ \\ | \\ | |/ ___| ____| | |___ /
/ _ \\ | \\| | | _| _| | | |_ \\
/ ___ \\| |\\ | |_| | |___| |___ ___) |
/_/ \\_\\_| \\_|\\____|_____|_____|____/
''';
static const String asciiArtOld = '''
____________ ________________________ ____________ ________________________
___ |__ | / /_ ____/__ ____/__ / ___ |__ | / /_ ____/__ ____/__ /
__ /| |_ |/ /_ / __ __ __/ __ / __ /| |_ |/ /_ / __ __ __/ __ /
@ -139,7 +158,7 @@ _ ___ | /| / / /_/ / _ /___ _ /___
/// Starts a number of isolates, running identical instances of an Angel application. /// Starts a number of isolates, running identical instances of an Angel application.
Future run(List<String> args) async { Future run(List<String> args) async {
late pub_sub.Server server; pub_sub.Server? server;
try { try {
var argResults = RunnerOptions.argParser.parse(args); var argResults = RunnerOptions.argParser.parse(args);
@ -153,11 +172,11 @@ _ ___ | /| / / /_/ / _ /___ _ /___
} }
} }
print(darkGray.wrap(asciiArt.trim() + print(darkGray.wrap(asciiArt +
'\n\n' + '\n\n' +
'A batteries-included, full-featured, full-stack framework in Dart.' + 'A batteries-included, full-featured, full-stack framework in Dart.' +
'\n\n' + '\n\n' +
'https://angel-dart.github.io\n')); 'https://angel3-framework.web.app\n'));
if (argResults['help'] == true) { if (argResults['help'] == true) {
stdout..writeln('Options:')..writeln(RunnerOptions.argParser.usage); stdout..writeln('Options:')..writeln(RunnerOptions.argParser.usage);
@ -191,7 +210,7 @@ _ ___ | /| / / /_/ / _ /___ _ /___
..writeln(red.wrap(st.toString())); ..writeln(red.wrap(st.toString()));
exitCode = 1; exitCode = 1;
} finally { } finally {
await server.close(); await server?.close();
} }
} }

View file

@ -1,7 +1,8 @@
name: angel3_production name: angel3_production
version: 3.0.1 version: 3.0.2
description: Helpers for concurrency, message-passing, rotating loggers, and other production functionality in Angel. description: Helpers for concurrency, message-passing, rotating loggers, and other production functionality in Angel3.
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/production homepage: https://angel3-framework.web.app
repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/production
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies: