Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove isolates from the analyzer service. #8509

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/lib/search/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class SearchBackend {
///
/// When other process has the claim, the loop waits a minute before
/// attempting to get the claim.
Future<Never> updateSnapshotInForeverLoop() async {
Future<void> updateSnapshotInForeverLoop() async {
final lock = GlobalLock.create(
'$runtimeVersion/search/update-snapshot',
expiration: Duration(minutes: 20),
Expand Down
53 changes: 8 additions & 45 deletions app/lib/service/entrypoint/analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import '../../task/backend.dart';
import '../../tool/neat_task/pub_dev_tasks.dart';

import '../download_counts/backend.dart';
import '_isolate.dart';

final Logger logger = Logger('pub.analyzer');

Expand All @@ -34,56 +33,20 @@ class AnalyzerCommand extends Command {
Future<void> run() async {
envConfig.checkServiceEnvironment(name);
await withServices(() async {
final worker =
await startWorkerIsolate(logger: logger, entryPoint: _workerMain);
registerScopeExitCallback(worker.close);
await downloadCountsBackend.start();
await taskBackend.start();
registerScopeExitCallback(() => taskBackend.stop());

final indexBuilder = await startWorkerIsolate(
logger: logger,
entryPoint: _indexBuilderMain,
kind: 'index-builder',
);
registerScopeExitCallback(indexBuilder.close);
setupPeriodTaskSchedulers();
// TODO: rewrite this loop to have a start/stop logic
scheduleMicrotask(searchBackend.updateSnapshotInForeverLoop);

if (activeConfiguration.exportedApiBucketName != null) {
final apiExporterIsolate = await startWorkerIsolate(
logger: logger,
entryPoint: _apiExporterMain,
kind: 'api-exporter',
);
registerScopeExitCallback(apiExporterIsolate.close);
await apiExporter!.start();
registerScopeExitCallback(() => apiExporter!.stop());
}

await runHandler(logger, analyzerServiceHandler);
});
}
}

Future _workerMain(EntryMessage message) async {
message.protocolSendPort.send(ReadyMessage());

await downloadCountsBackend.start();
await taskBackend.start();
registerScopeExitCallback(() => taskBackend.stop());

setupPeriodTaskSchedulers();

// wait indefinitely
await Completer().future;
}

Future _indexBuilderMain(EntryMessage message) async {
message.protocolSendPort.send(ReadyMessage());
await downloadCountsBackend.start();
await searchBackend.updateSnapshotInForeverLoop();
}

Future _apiExporterMain(EntryMessage message) async {
message.protocolSendPort.send(ReadyMessage());
await downloadCountsBackend.start();
await apiExporter!.start();
registerScopeExitCallback(() => apiExporter!.stop());

// wait indefinitely
await Completer().future;
}
Loading