Skip to content

Non-nullable ApiExporter instance in scope. #8790

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

Merged
merged 1 commit into from
May 26, 2025
Merged
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
4 changes: 2 additions & 2 deletions app/lib/admin/actions/exported_api_sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Optionally, write rewrite of all files using:
final packagesOpt = options['packages'] ?? '';
final syncAll = packagesOpt == 'ALL';
if (syncAll) {
await apiExporter!.synchronizeExportedApi(forceWrite: forceWrite);
await apiExporter.synchronizeExportedApi(forceWrite: forceWrite);
return {
'packages': 'ALL',
'forceWrite': forceWrite,
Expand All @@ -50,7 +50,7 @@ Optionally, write rewrite of all files using:
InvalidInputException.checkPackageName(p);
}
for (final p in packages) {
await apiExporter!.synchronizePackage(p, forceWrite: forceWrite);
await apiExporter.synchronizePackage(p, forceWrite: forceWrite);
}
return {
'packages': packages,
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/actions/moderate_package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Note: the action may take a longer time to complete as the public archive bucket
await purgePackageCache(package);

// sync exported API(s)
await apiExporter?.synchronizePackage(package, forceDelete: true);
await apiExporter.synchronizePackage(package, forceDelete: true);

// retract or re-populate public archive files
await packageBackend.tarballStorage.updatePublicArchiveBucket(
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/actions/moderate_package_versions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Set the moderated flag on a package version (updating the flag and the timestamp
await purgePackageCache(package);

// sync exported API(s)
await apiExporter?.synchronizePackage(package, forceDelete: true);
await apiExporter.synchronizePackage(package, forceDelete: true);

// retract or re-populate public archive files
await packageBackend.tarballStorage.updatePublicArchiveBucket(
Expand Down
2 changes: 1 addition & 1 deletion app/lib/fake/server/fake_server_entrypoint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Future<shelf.Response> _testProfile(shelf.Request rq) async {
// ignore: invalid_use_of_visible_for_testing_member
await importProfile(profile: profile);
final analysis = (map['analysis'] as String?) ?? 'fake';
await apiExporter!.synchronizeExportedApi();
await apiExporter.synchronizeExportedApi();
await processTaskFakeLocalOrWorker(analysis);
return shelf.Response.ok('{}');
}
Expand Down
4 changes: 2 additions & 2 deletions app/lib/package/api_export/api_exporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ final Logger _log = Logger('api_export.api_exporter');
void registerApiExporter(ApiExporter value) =>
ss.register(#_apiExporter, value);

/// The active API Exporter service or null if it hasn't been initialized.
ApiExporter? get apiExporter => ss.lookup(#_apiExporter) as ApiExporter?;
/// The API Exporter service.
ApiExporter get apiExporter => ss.lookup(#_apiExporter) as ApiExporter;

const _concurrency = 50;

Expand Down
6 changes: 2 additions & 4 deletions app/lib/package/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1320,10 +1320,8 @@ class PackageBackend {
if (activeConfiguration.isPublishedEmailNotificationEnabled)
emailBackend.trySendOutgoingEmail(outgoingEmail),
taskBackend.trackPackage(newVersion.package, updateDependents: true),
if (apiExporter != null) ...[
apiExporter!.synchronizePackage(newVersion.package),
apiExporter!.synchronizeAllPackagesAtomFeed(),
],
apiExporter.synchronizePackage(newVersion.package),
apiExporter.synchronizeAllPackagesAtomFeed(),
]);
await tarballStorage.updateContentDispositionOnPublicBucket(
newVersion.package, newVersion.version!);
Expand Down
7 changes: 2 additions & 5 deletions app/lib/service/entrypoint/analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:gcloud/service_scope.dart';
import 'package:logging/logging.dart';
import 'package:pub_dev/package/api_export/api_exporter.dart';
import 'package:pub_dev/search/backend.dart';
import 'package:pub_dev/shared/configuration.dart';

import '../../analyzer/handlers.dart';
import '../../service/services.dart';
Expand Down Expand Up @@ -41,10 +40,8 @@ class AnalyzerCommand extends Command {
// TODO: rewrite this loop to have a start/stop logic
scheduleMicrotask(searchBackend.updateSnapshotInForeverLoop);

if (activeConfiguration.exportedApiBucketName != null) {
await apiExporter!.start();
registerScopeExitCallback(() => apiExporter!.stop());
}
await apiExporter.start();
registerScopeExitCallback(() => apiExporter.stop());

await runHandler(logger, analyzerServiceHandler);
});
Expand Down
13 changes: 5 additions & 8 deletions app/lib/service/services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,11 @@ Future<R> _withPubServices<R>(FutureOr<R> Function() fn) async {
registerAccountBackend(AccountBackend(dbService));
registerAdminBackend(AdminBackend(dbService));
registerAnnouncementBackend(AnnouncementBackend());
if (activeConfiguration.exportedApiBucketName != null) {
registerApiExporter(ApiExporter(
dbService,
storageService: storageService,
bucket:
storageService.bucket(activeConfiguration.exportedApiBucketName!),
));
}
registerApiExporter(ApiExporter(
dbService,
storageService: storageService,
bucket: storageService.bucket(activeConfiguration.exportedApiBucketName!),
));
registerAsyncQueue(AsyncQueue());
registerAuditBackend(AuditBackend(dbService));
registerConsentBackend(ConsentBackend(dbService));
Expand Down
2 changes: 1 addition & 1 deletion app/lib/shared/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ final class Configuration {
publicPackagesBucketName!,
searchSnapshotBucketName!,
taskResultBucketName!,
if (exportedApiBucketName != null) exportedApiBucketName!,
exportedApiBucketName!,
]);

late final isProduction = projectId == 'dartlang-pub';
Expand Down
2 changes: 1 addition & 1 deletion app/lib/tool/neat_task/pub_dev_tasks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ List<NeatPeriodicTaskScheduler> createPeriodicTaskSchedulers({
_daily(
name: 'synchronize-exported-api',
isRuntimeVersioned: true,
task: () async => await apiExporter?.synchronizeExportedApi(),
task: () async => await apiExporter.synchronizeExportedApi(),
),

// Deletes moderated packages, versions, publishers and users.
Expand Down
12 changes: 6 additions & 6 deletions app/test/package/api_export/api_exporter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ void main() {
// we cannot use an isolated instance, we need to use the same setup.
// However, for better control and consistency, we can remove all the
// existing files from the bucket at the start of this test:
await apiExporter!.stop();
await apiExporter.stop();
final bucket =
storageService.bucket(activeConfiguration.exportedApiBucketName!);
await _deleteAll(bucket);

await _testExportedApiSynchronization(
bucket,
apiExporter!.synchronizeExportedApi,
apiExporter.synchronizeExportedApi,
);
});

Expand All @@ -75,21 +75,21 @@ void main() {
// we cannot use an isolated instance, we need to use the same setup.
// However, for better control and consistency, we can remove all the
// existing files from the bucket at the start of this test:
await apiExporter!.stop();
await apiExporter.stop();
final bucket =
storageService.bucket(activeConfiguration.exportedApiBucketName!);
await _deleteAll(bucket);

await apiExporter!.synchronizeExportedApi();
await apiExporter.synchronizeExportedApi();

await apiExporter!.start();
await apiExporter.start();

await _testExportedApiSynchronization(
bucket,
() async => await clockControl.elapse(minutes: 15),
);

await apiExporter!.stop();
await apiExporter.stop();
},
);
}
Expand Down
Loading