batch 0.1.0 copy "batch: ^0.1.0" to clipboard
batch: ^0.1.0 copied to clipboard

outdated

A lightweight and powerful batch library written in Dart. You can easily create a CLI batch program in Dart with this library.

example/example.dart

// Copyright (c) 2022, Kato Shinya. All rights reserved.
// Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:batch/batch.dart';

void main() {
  final job1 = Job.from(name: 'Job1', cron: '*/1 * * * *')
    ..nextStep(
      Step.from(name: 'Step1')
        ..nextTask(TestTask())
        ..nextTask(SayHelloTask())
        ..nextTask(SayWorldTask()),
    )
    ..nextStep(
      Step.from(name: 'Step2')
        ..nextTask(TestTask())
        ..nextTask(SayHelloTask())
        ..nextTask(SayWorldTask()),
    );

  final job2 = Job.from(name: 'Job2', cron: '*/3 * * * *')
    ..nextStep(
      Step.from(name: 'Step1')
        ..nextTask(SayHelloTask())
        ..nextTask(SayWorldTask()),
    );

  JobLauncher.newInstance()
    ..addJob(job1)
    ..addJob(job2)
    ..execute();
}

class TestTask extends Task {
  static int count = 0;

  @override
  Future<RepeatStatus> execute() async {
    if (count == 5) {
      print('Finish.');
      return RepeatStatus.finished;
    }

    count++;

    print('Continue.');
    return RepeatStatus.continuable;
  }
}

class SayHelloTask extends Task {
  @override
  Future<RepeatStatus> execute() async {
    print('Hello,');
    return RepeatStatus.finished;
  }
}

class SayWorldTask extends Task {
  @override
  Future<RepeatStatus> execute() async {
    print('World!');
    return RepeatStatus.finished;
  }
}
28
likes
0
pub points
53%
popularity

Publisher

verified publishershinyakato.dev

A lightweight and powerful batch library written in Dart. You can easily create a CLI batch program in Dart with this library.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

cron

More

Packages that depend on batch