dart-lang/bazel_worker

Name: bazel_worker

Owner: Dart

Description: Dart integration for Bazel build system

Created: 2016-04-11 18:30:35.0

Updated: 2018-05-18 16:44:37.0

Pushed: 2018-05-18 16:45:21.0

Homepage: https://pub.dartlang.org/packages/bazel_worker

Size: 58

Language: Dart

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Tools for creating a persistent worker loop for bazel.

Usage

There are two abstract classes provided by this package, AsyncWorkerLoop and SyncWorkerLoop. These each have a performRequest method which you must implement.

Lets look at a simple example of a SyncWorkerLoop implementation:

rt 'dart:io';
rt 'package:bazel_worker/bazel_worker.dart';

 main() {
 Blocks until it gets an EOF from stdin.
w SyncSimpleWorker().run();


s SyncSimpleWorker extends SyncWorkerLoop {
/ Must synchronously return a [WorkResponse], since this is a
/ [SyncWorkerLoop].
rkResponse performRequest(WorkRequest request) {
new File('hello.txt').writeAsStringSync('hello world!');
return new WorkResponse()..exitCode = EXIT_CODE_OK;


And now the same thing, implemented as an AsyncWorkerLoop:

rt 'dart:io';
rt 'package:bazel_worker/bazel_worker.dart';

 main() {
 Doesn't block, runs tasks async as they are received on stdin.
w AsyncSimpleWorker().run();


s AsyncSimpleWorker extends AsyncWorkerLoop {
/ Must return a [Future<WorkResponse>], since this is an
/ [AsyncWorkerLoop].
ture<WorkResponse> performRequest(WorkRequest request) async {
await new File('hello.txt').writeAsString('hello world!');
return new WorkResponse()..exitCode = EXIT_CODE_OK;


As you can see, these are nearly identical, it mostly comes down to the constraints on your package and personal preference which one you choose to implement.

Testing

A package:bazel_worker/testing.dart file is also provided, which can greatly assist with writing unit tests for your worker. See the test/worker_loop_test.dart test included in this package for an example of how the helpers can be used.

Features and bugs

Please file feature requests and bugs at the issue tracker.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.