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

Pin task may never complete #16

Open
pcfreak30 opened this issue Jan 26, 2024 · 0 comments
Open

Pin task may never complete #16

pcfreak30 opened this issue Jan 26, 2024 · 0 comments

Comments

@pcfreak30
Copy link

Here is a patched version an an example:

import 'dart:async';
import 'dart:io';

import 'package:lib5/lib5.dart';
import 'package:pool/pool.dart';
import 'package:vup/generic/state.dart';
import 'package:vup/model/sync_task.dart';

import 'task.dart';

class PinningQueueTask extends QueueTask {
  @override
  final String id;
  @override
  final List<String> dependencies;
  @override
  final threadPool = 'pin';

  final String remote;
  final List<CID> cids;

  @override
  double get progress => _progress / cids.length;

  int _progress = 0;

  PinningQueueTask({
    required this.id,
    required this.dependencies,
    required this.remote,
    required this.cids,
  });

  bool isCancelled = false;

  final pool = Pool(8);
@override
  void cancel() {
    isCancelled = true;
  }

  @override
  Future<void> execute() async {
    logger.verbose('pinning ${cids.length} CIDs on $remote');
    final completer = Completer();

    for (final cid in cids) {
      final pins = pinningService.getPinsForHash(
        cid.hash,
      );
      if (!pins.contains(remote)) {
        try {
          if (remote == '_local') {
            pool.withResource(() async {
              if (isCancelled) return;
              await s5Node.pinCID(cid);

              _progress++;

              if (progress == cids.length) completer.complete();
            });
          } else {
            final sc = mySky.storageServiceConfigs
                .firstWhere((e) => e.authority == remote);

            pool.withResource(() async {
              if (isCancelled) return;
              final res = await mySky.httpClient.post(
                sc.getAccountsAPIUrl(
                  '/s5/pin/${cid.toBase64Url()}',
                ),
                headers: sc.headers,
              );
              res.expectStatusCode(200);

              _progress++;

              if (progress == cids.length) completer.complete();
            });
          }
        } catch (e, st) {
          logger.catched(e, st);
        }
      }
      else{
        _progress++;
      }
    }

    if (progress == cids.length) completer.complete();

    await completer.future;
  }
}

added else{ _progress++; } and if (progress == cids.length) completer.complete();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant