p-hatan/ mirror

pub repository

mirror.p-hatan.ir

bazel_worker

1.1.0

Protocol and utilities to implement or invoke persistent bazel workers.

Download archive

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:

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

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

class SyncSimpleWorker extends SyncWorkerLoop {
  /// Must synchronously return a [WorkResponse], since this is a
  /// [SyncWorkerLoop].
  WorkResponse performRequest(WorkRequest request) {
    File('hello.txt').writeAsStringSync('hello world!');
    return 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.
  AsyncSimpleWorker().run();
}

class AsyncSimpleWorker extends AsyncWorkerLoop {
  /// Must return a [Future<WorkResponse>], since this is an
  /// [AsyncWorkerLoop].
  Future<WorkResponse> performRequest(WorkRequest request) async {
    await File('hello.txt').writeAsString('hello world!');
    return 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.

Changelog

1.1.0

  • Add constructors with named parameters to the generated worker protocol messages.
  • Include comments on the generated worker protocol API.

1.0.3

  • Require package:protobuf >= 3.0.0.
  • Require Dart SDK >= 2.19.0

1.0.2

  • Expand pub documentation to improve pub score.

1.0.1

  • Require Dart SDK >=2.14.0
  • Drop dependency on package:pedantic.

1.0.0

  • Improve AsyncMessageGrouper performance.
  • Add benchmark/benchmark.dart measuring AsyncMessageGrouper performance.

1.0.0-nullsafety.0

  • Migrate to null safety.
  • Use WorkResponse with exitCode set to EXIT_CODE_BROKEN_PIPE instead of null responses.

0.1.25+1-dev

  • Regenerate proto code and fix some new analysis hints.

0.1.25

  • Add isBroadcast implementation to TestStdin classes.

0.1.24

  • Check for closed port when trying to read a response in IsolateDriverConnection and return null if there is nothing to be read.

0.1.23+1

  • Don't rely on exitCode to know when a worker terminates, instead wait for the input stream to close.
    • The SDK may also start throwing instead of returning a null here, so this pre-emptively guards against that.

0.1.23

  • Support protobuf 1.x.
  • Added a tool for updating generated proto files and updated them using the latest version of the protoc_plugin package.
    • This required a lower bound bump of the protobuf package to 0.14.4.

0.1.22

  • Require protobuf 0.14.0.

0.1.21+1

  • Don't rely on exitCode to know when a worker terminates, instead wait for the input stream to close. Backport of fix in 0.1.23+1 in a version that does not require a newer protobuf.

0.1.21

  • Make TestStdinAsync behave like a Stream<Uint8List>

0.1.20

  • Close worker outputStream on cancel.

0.1.19

0.1.18

  • Add a trackWork optional named argument to BazelDriver.doWork. This allows the caller to know when a work request is actually sent to a worker.

0.1.17

  • Allow protobuf 0.13.0.

0.1.16

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

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> (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.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add bazel_worker
pubspec.yaml
name: bazel_worker
version: 1.1.0
description: >-
  Protocol and utilities to implement or invoke persistent bazel workers.
repository: https://github.com/dart-lang/bazel_worker

environment:
  sdk: '>=2.19.0 <4.0.0'

dependencies:
  async: ^2.5.0
  protobuf: ^3.0.0

dev_dependencies:
  dart_flutter_team_lints: ^1.0.0
  test: ^1.16.0

Version history

VersionPublishedArchiveSHA-256
0.1.02016-04-13T16:46:28.330ZDownloadb410f8f142b49e4e13ad35150d8b0f35fa324bc4d246d9b91b9487483d5dd94d
0.1.12016-04-15T19:15:42.294ZDownloadccddcfd73b1c8f8c7c84ae9caf8613eb025f2ac850c9bd1b4d180d145139d20a
0.1.22017-01-19T20:21:42.190ZDownload946c12da145ec48934e4142a4eed36360b6cdc02acd68f2381237c6210a1d9d3
0.1.32017-03-20T17:31:03.933948ZDownloadac81714613d59fe3fa40651362012d9bd151762f6f10f5c22be31b74d955f85b
0.1.42017-04-05T19:18:11.352112ZDownloada235bb710d5ec302ab0c817ee6da7af991a4b5790ef25821efef13d9364a7111
0.1.52017-11-03T17:15:30.768658ZDownload00434474d49d9af23838c94ebe0a64097360f36f14edf7fee7357ac56c73b78e
0.1.62017-11-03T18:21:35.638369ZDownload1bd5d2d731f5fafccc434d2621fd10313f586661448ec75425a4a929a55814fb
0.1.72017-11-21T17:06:57.964933ZDownload89fb7d10aecf6b5b15b305e07df99164b3b49de4348c2d02a21ee26f348f9dcd
0.1.82017-11-27T22:23:08.693586ZDownloadb627ae9127f59ca38e604b1c368e51e531433bf4423bc97a7bb79c860959a52f
0.1.92018-01-16T14:59:32.691859ZDownloadd5eee2150c83bba8a51af3dc4adcae2291cd4d6df34e1b6908030e05e0e64231
0.1.102018-05-18T16:45:01.816966ZDownload5bac6e844cef9fcfe50dcec179cb4ef2db170e080fd1e10e6fa43499ac6edd2c
0.1.112018-07-10T16:49:41.533567ZDownload7df2c2867bb5895b1c585df72342e85f5947eeb7cb4068315b3b2f32e12f1a1b
0.1.122018-07-16T15:47:28.434193ZDownloadef593a5147eacfbd6e23321f6c142b05743ddda928462f2ba8742b58ddb661c0
0.1.132018-09-06T14:37:54.837103ZDownload91750e77a6dccceb1d406d67a30deca617c093109a3a9b305bd700cf5e222d88
0.1.142018-09-17T14:48:46.938515ZDownload7fd2ceca540b24d7457602c0ed941240f1f5a3fbb649bb4cd5765852f9b78a41
0.1.152018-10-22T17:19:07.489773ZDownload9f5fe140684000f47378cebf3ad7779a6838bab1633194f154c550b7c7ec6e9c
0.1.162019-01-10T15:19:55.765654ZDownload0436c07c56035753d2b40c42c14a25f31eb4aca16e3ed4a2f2cdd58c0a515f78
0.1.172019-01-24T16:27:16.046156ZDownload21c6b6dc0837674063b604154a3d22f71a720cb6f0af78276a7f9099bd04bb99
0.1.182019-01-28T22:28:44.118055ZDownloade43a5ba6f15e39dfc97b56930db1f0501ed208c1c82110ed628c0bae211782c4
0.1.192019-02-07T16:12:43.132859ZDownload5f16c3aba9b8b31365074319190e5d1262a50b20f35781217675e876c5ac2c5c
0.1.202019-02-12T18:40:20.050189ZDownload4769d7df87e70b2c91f3dc68138eaab4aa8d5fb0cb65d29c76d04f9611f7ab9d
0.1.212019-05-20T16:22:48.651195ZDownloada92e8d7f53c2320579ecfa7949945668c4e9f53fc07084d1fdec6f39239369e6
0.1.21+12020-05-04T18:06:09.251491ZDownload0fdcb200ab59642fb8761771d3a3525b4e4b3256333f85525da49ad0df364418
0.1.222019-09-12T16:02:19.089392ZDownload9b78011b0a317044319457e330bd02d62d32bc1e83d8a893ffc9b9c7a8bfa0c7
0.1.232019-10-21T15:54:16.173085ZDownload77e75dc02602d8a950e54fdb7d0bd46de1dd798d3e7f064b6a9c1dcd62398993
0.1.23+12020-02-04T22:36:33.879184ZDownload7f5e24bf54d7402a8748f35da421d4d7ea0d26b016f3d8b3d11e23158b269305
0.1.242020-06-01T13:51:35.751385ZDownloadcc64734920627c2f2af6e400d687be63eaa1d83b7ab76e248b9e40aae1761ca1
0.1.252020-07-06T19:52:40.773623ZDownload45aea72e83bd3ed8923d51a5614c87cc04fa8ffb8392ddfb506db8126383cc62
1.0.0-nullsafety.02021-02-04T15:59:27.277527ZDownloadefaa4d7aa4191bc794ea3faf0db769a83ab0d45c26b849910f7b9f94bb37abaf
1.0.02021-03-08T16:58:12.511197ZDownload8a10b711ceead25ed7c42e135679efe7e27fe8cd9989fa5cd630a9c5731ddc6c
1.0.12021-10-05T16:43:03.515317ZDownloadb0f16544323bfc3ba1d879e6b65eee07508009023d51e89978f261cf9853187f
1.0.22022-10-18T16:48:04.156342ZDownload500584fdb80bcb70a2990a5838338a757cc24bbf27d88bf791cbe9461c57cd5a
1.0.32023-06-16T15:44:36.331803ZDownload6aa1de567844e1a1db3ac16959159b31a71128fdd27d63d861ad5aa7299e48c5
1.1.02023-08-31T18:08:38.831490ZDownload6f306845d941808bed2fdbd7db3a39de273a8248a9303cfebf0cfa861372616e
1.1.12024-03-07T16:06:03.914986ZDownload4eef19cc486c289e4b06c69d0f6f3192e85cc93c25d4d15d02afb205e388d2f0
1.1.22024-10-29T14:35:02.583620ZDownload57035594b87d9f5af99f1a80e1edf5411dadbdf5acfc4f90403e3849f57dd0f0
1.1.32025-04-01T17:47:48.076117ZDownload373a6ef07caa6c674c1cf144a5fe1e0f712c040552031ce669f298e35f7e110a
1.1.42025-10-07T07:42:28.435856ZDownload47e5106e06dcbfd7382b903b676d48974387b8612ca470f6c54f367ca90da32b
1.1.52025-12-02T19:41:17.023023ZDownload87cae9150fcf9942b8057e5f51c4848a3efde1289e97411e1c8f01e350120999

Dependencies

async "^2.5.0"

protobuf "^3.0.0"