Scalable?

This commit is contained in:
thosakwe 2016-12-24 11:12:50 -05:00
parent b55c687641
commit 02d378dedf
4 changed files with 50 additions and 26 deletions

11
bin/cluster.dart Normal file
View file

@ -0,0 +1,11 @@
/// This should be used with `multiserver` as an entry
/// point for `spawnIsolates`.
library angel.cluster;
import 'dart:async';
import 'common.dart';
main() async {
runZoned(startServer(clustered: true), onError: onError);
}

34
bin/common.dart Normal file
View file

@ -0,0 +1,34 @@
import 'dart:io';
import 'dart:isolate';
import 'package:angel/angel.dart';
import 'package:angel_diagnostics/angel_diagnostics.dart';
import 'package:intl/intl.dart';
startServer({bool clustered: false}) {
return (args, [SendPort sendPort]) async {
var app = await createServer();
var dateFormat = new DateFormat("y-MM-dd");
var logFile = new File("logs/${dateFormat.format(new DateTime.now())}.txt");
InternetAddress host;
int port;
if (!clustered) {
host = new InternetAddress(app.properties['host']);
port = app.properties['port'];
} else {
host = InternetAddress.LOOPBACK_IP_V4;
port = 0;
}
var server =
await new DiagnosticsServer(app, logFile).startServer(host, port);
sendPort?.send([server.address.address, server.port]);
};
}
onError(error, [StackTrace stackTrace]) {
stderr.writeln("Unhandled error occurred: $error");
if (stackTrace != null) {
stderr.writeln(stackTrace);
}
}

View file

@ -1,28 +1,7 @@
#!/usr/bin/env dart #!/usr/bin/env dart
import 'dart:async'; import 'dart:async';
import 'dart:io'; import 'common.dart';
import 'package:angel/angel.dart';
import 'package:angel_diagnostics/angel_diagnostics.dart';
import 'package:intl/intl.dart';
main() async { main() async {
runZoned(startServer, onError: onError); runZoned(startServer(), onError: onError);
}
startServer() async {
var app = await createServer();
var dateFormat = new DateFormat("y-MM-dd");
var logFile = new File("logs/${dateFormat.format(new DateTime.now())}.txt");
var host = new InternetAddress(app.properties['host']);
var port = app.properties['port'];
await new DiagnosticsServer(app, logFile).startServer(host, port);
}
onError(error, [StackTrace stackTrace]) {
stderr.writeln("Unhandled error occurred: $error");
if (stackTrace != null) {
stderr.writeln(stackTrace);
}
} }

View file

@ -28,9 +28,9 @@ class AuthController extends Controller {
// Wire up local authentication, connected to our User service // Wire up local authentication, connected to our User service
auth = new AngelAuth(jwtKey: app.jwt_secret) auth = new AngelAuth(jwtKey: app.jwt_secret)
..serializer = serializer ..serializer = serializer
..deserializer = deserializer; ..deserializer = deserializer
..strategies ..strategies.add(
.add(new LocalAuthStrategy(verifier(app.container.make(UserService)))); new LocalAuthStrategy(verifier(app.container.make(UserService))));
await super.call(app); await super.call(app);
await app.configure(auth); await app.configure(auth);