bazel_worker 0.1.15

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 66

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:

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

void main() {
  // Blocks until it gets an EOF from stdin.
  new SyncSimpleWorker().run();
}

class SyncSimpleWorker extends SyncWorkerLoop {
  /// Must synchronously return a [WorkResponse], since this is a
  /// [SyncWorkerLoop].
  WorkResponse 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:

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

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

class AsyncSimpleWorker extends AsyncWorkerLoop {
  /// Must return a [Future<WorkResponse>], since this is an
  /// [AsyncWorkerLoop].
  Future<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.

0.1.15

  • Update the worker_protocol.pb.dart file with the latest proto generator.
  • Require protobuf 0.10.4.

0.1.14

  • Allow workers to support running in isolates. To support running in isolates, workers must modify their main method to accept a SendPort then use it when creating the AsyncWorkerConnection. See async_worker in e2e_test.

0.1.13

  • Support protobuf 0.10.0.

0.1.12

  • Set max SDK version to <3.0.0.

0.1.11

  • Added support for protobuf 0.9.0.

0.1.10

  • Update the SDK dependency to 2.0.0-dev.17.0.
  • Update to protobuf version 0.8.0
  • Remove usages of deprecated upper-case constants from the SDK.

0.1.9

  • Update the worker_protocol.pb.dart file with the latest proto generator.

0.1.8

  • Add Future cancel() method to DriverConnection, which in the case of a StdDriverConnection closes the input stream.
    • The terminateWorkers method on BazelWorkerDriver now calls cancel on all worker connections to ensure the vm can exit correctly.

0.1.7

  • Update the BazelWorkerDriver class to handle worker crashes, and retry work requests. The number of retries is configurable with the new int maxRetries optional arg to the BazelWorkerDriver constructor.

0.1.6

  • Update the worker_protocol.pb.dart file with the latest proto generator.
  • Add support for package:async 2.x and package:protobuf 6.x.

0.1.5

  • Change TestStdinAsync.controller to StreamController<List<int>> (instead of using dynamic as the type argument).

0.1.4

  • Added BazelWorkerDriver class, which can be used to implement the bazel side of the protocol. This allows you to speak to any process which knows the bazel protocol from your own process.
  • Changed WorkerConnection#readRequest to return a FutureOr<WorkRequest> instead of dynamic.

0.1.3

  • Add automatic intercepting of print calls and append them to response.output. This makes more libraries work out of the box, as printing would previously cause an error due to communication over stdin/stdout.
    • Note that using stdin/stdout directly will still cause an error, but that is less common.

0.1.2

  • Add better handling for the case where stdin gives an error instead of an EOF.

0.1.1

  • Export AsyncMessageGrouper and SyncMessageGrouper as part of the testing library. These can assist when writing e2e tests and communicating with a worker process.

0.1.0

  • Initial version.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  bazel_worker: ^0.1.15

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:bazel_worker/bazel_worker.dart';
  
Version Uploaded Documentation Archive
0.1.15 Oct 22, 2018 Go to the documentation of bazel_worker 0.1.15 Download bazel_worker 0.1.15 archive
0.1.14 Sep 17, 2018 Go to the documentation of bazel_worker 0.1.14 Download bazel_worker 0.1.14 archive
0.1.13 Sep 6, 2018 Go to the documentation of bazel_worker 0.1.13 Download bazel_worker 0.1.13 archive
0.1.12 Jul 16, 2018 Go to the documentation of bazel_worker 0.1.12 Download bazel_worker 0.1.12 archive
0.1.11 Jul 10, 2018 Go to the documentation of bazel_worker 0.1.11 Download bazel_worker 0.1.11 archive
0.1.10 May 18, 2018 Go to the documentation of bazel_worker 0.1.10 Download bazel_worker 0.1.10 archive
0.1.9 Jan 16, 2018 Go to the documentation of bazel_worker 0.1.9 Download bazel_worker 0.1.9 archive
0.1.8 Nov 27, 2017 Go to the documentation of bazel_worker 0.1.8 Download bazel_worker 0.1.8 archive
0.1.7 Nov 21, 2017 Go to the documentation of bazel_worker 0.1.7 Download bazel_worker 0.1.7 archive
0.1.6 Nov 3, 2017 Go to the documentation of bazel_worker 0.1.6 Download bazel_worker 0.1.6 archive

All 16 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
44
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
66
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: Flutter, other

Primary library: package:bazel_worker/bazel_worker.dart with components: io, isolate.

Health suggestions

Format lib/src/worker_protocol.pb.dart.

Run dartfmt to format lib/src/worker_protocol.pb.dart.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use bazel_worker.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.17.0 <3.0.0
async >1.9.0 <3.0.0 2.0.8
protobuf >=0.10.4 <0.11.0 0.10.5
Transitive dependencies
collection 1.14.11
fixnum 0.10.9
Dev dependencies
test ^1.2.0