Giter VIP home page Giter VIP logo

isolate_woker's People

Contributors

anlam87 avatar anlamfilestring87 avatar trietbui85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

isolate_woker's Issues

cancel not work

I followed your example , but cancel is not working, cancelToken is always null in handleCancel()

class BackupTask implements FileTask<Future<bool>> {
  final BackupRoutineModel rotinaBackup;
  LibsshWrapper libssh;
  LibsshCancelToken cancelToken;

  BackupTask(this.rotinaBackup, {this.taskId}) {}
  @override
  Future<bool> execute() {
    return _doExecute();
  }

  Future<bool> _doExecute() async {
    var completer = Completer<bool>();
    cancelToken = LibsshCancelToken();
    try {
     
      var server = rotinaBackup.servers.first;
      libssh = LibsshWrapper(
        server.host,
        username: server.user,
        password: server.password,
        port: server.port,
        verbosity: false,
      );
      libssh.connect();

      List<DirectoryItem> fileObjects = server.fileObjects;
      int totalSize = 0;
      int totalLoaded = 0;

      totalSize = fileObjects
          .map((d) => libssh.getSizeOfFileSystemItem(d))
          .toList()
          .reduce((value, element) => value + element);

      final start = DateTime.now();
      for (var item in fileObjects) {
        if (item.type == DirectoryItemType.directory) {
          await libssh.scpDownloadDirectory(
            item.path,
            rotinaBackup.destinationDirectory,
            printLog: (v) {
              tasklogCallback(v);
            },
            callbackStats: (int total, int loaded, int currentFileSize,
                int countDirectory, int countFiles) {
              print('i');
              totalLoaded += currentFileSize;
              taskProgressCallback(totalSize, totalLoaded, 'a');
            },
            cancelToken: cancelToken,
          );
        } else if (item.type == DirectoryItemType.file) {
          var currentFileSize = 0;
          await libssh.scpDownloadFileTo(
            item.path,
            '${rotinaBackup.destinationDirectory}/${item.name}',
            callbackStats: (int total, int loaded) {
              currentFileSize = loaded;
            },
            recursive: false,
          );

          totalLoaded += currentFileSize;
          taskProgressCallback(totalSize, totalLoaded, 'a');
        }
        if (cancelToken.isCancelled) {
          break;
        }
      }

      tasklogCallback('${DateTime.now().difference(start)}');
      completer.complete(true);
    } catch (e, s) {
      tasklogCallback('BackupTask ${rotinaBackup.name} error: $e $s');
      completer.completeError(e);
    } finally {
     
      libssh.dispose();
    }

    return completer.future;
  }

  @override
  String taskId;

  @override
  ActionType actionType = ActionType.download;

  ///Function(int total, int loaded, String status);
  @override
  ProgressCallback taskProgressCallback;

  @override
  void handleCancel(String taskId) {
//cancelToken is null
    print('BackupTask@handleCancel $cancelToken');
    cancelToken?.cancel('Cancel backup $taskId');
  }

  @override
  LogCallback tasklogCallback;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.