runWorkflow function

void runWorkflow({
  1. List<String> args = const [],
  2. FutureOr<void> argsConfigBuilder(
    1. ArgParser parser
    )?,
  3. FutureOr<Map<String, dynamic>> onLoadArgs(
    1. ArgResults args
    )?,
  4. required List<ScheduledJobBuilder> jobs,
  5. Map<String, dynamic> sharedParameters = const {},
  6. LogConfiguration? logConfig,
})

The main entry point of the batch application.

Schedules jobs passed as arguments and starts long-lived server-side processes. This jobs specification is required, and an exception will always be raised if the job to be scheduled does not exist.

You can also set parameters in shredParameters that can be shared by all layers of this application. This specification is useful for setting up data or singleton instances that you want to share with all jobs.

If you wish to use command line arguments in the life cycle of a batch application, pass command line arguments as arguments args. Also, the argument argsConfigBuilder is always required when argument args is specified. The argsConfigBuilder is a function for setting rules to parse args of type List<String> into a more manageable format, allowing you to use the well-known args library specification as is.

In addition, a possible use case for command line arguments is to use command line arguments to create a singleton instance at the start of an application. In this onLoadArgs function, ArgsResult parsed args according to the rules specified in argsConfigBuilder is passed in the callback.

Now all that remains is to return a Map with arbitrary keys and values using the data set in this ArgsResult. Only the data in this returned map will be registered as SharedParameters, and any command line arguments not specified in this map will be ignored.

You can see more details at Pub.dev or official examples.

Implementation

void runWorkflow({
  List<String> args = const [],
  FutureOr<void> Function(ArgParser parser)? argsConfigBuilder,
  FutureOr<Map<String, dynamic>> Function(ArgResults args)? onLoadArgs,
  required List<ScheduledJobBuilder> jobs,
  Map<String, dynamic> sharedParameters = const {},
  LogConfiguration? logConfig,
}) =>
    // TODO:The following lines should be removed after making the BatchApplication class private.
    // ignore: deprecated_member_use_from_same_package
    BatchApplication(
      args: args,
      argsConfigBuilder: argsConfigBuilder,
      onLoadArgs: onLoadArgs,
      jobs: jobs,
      sharedParameters: sharedParameters,
      logConfig: logConfig,
    )..run();