createJob method

Future<CreateJobResponse> createJob({
  1. required String jobId,
  2. required List<String> targets,
  3. AbortConfig? abortConfig,
  4. String? description,
  5. String? document,
  6. String? documentSource,
  7. JobExecutionsRolloutConfig? jobExecutionsRolloutConfig,
  8. String? namespaceId,
  9. PresignedUrlConfig? presignedUrlConfig,
  10. List<Tag>? tags,
  11. TargetSelection? targetSelection,
  12. TimeoutConfig? timeoutConfig,
})

Creates a job.

May throw InvalidRequestException. May throw ResourceNotFoundException. May throw ResourceAlreadyExistsException. May throw LimitExceededException. May throw ThrottlingException. May throw ServiceUnavailableException.

Parameter jobId : A job identifier which must be unique for your AWS account. We recommend using a UUID. Alpha-numeric characters, "-" and "_" are valid for use here.

Parameter targets : A list of things and thing groups to which the job should be sent.

Parameter abortConfig : Allows you to create criteria to abort a job.

Parameter description : A short text description of the job.

Parameter document : The job document.

The placeholder link is of the following form:

${aws:iot:s3-presigned-url:https://s3.amazonaws.com/bucket/key}

where bucket is your bucket name and key is the object in the bucket to which you are linking.

Parameter documentSource : An S3 link to the job document.

Parameter jobExecutionsRolloutConfig : Allows you to create a staged rollout of the job.

Parameter namespaceId : The namespace used to indicate that a job is a customer-managed job.

When you specify a value for this parameter, AWS IoT Core sends jobs notifications to MQTT topics that contain the value in the following format.

$aws/things/THING_NAME/jobs/JOB_ID/notify-namespace-NAMESPACE_ID/

Parameter presignedUrlConfig : Configuration information for pre-signed S3 URLs.

Parameter tags : Metadata which can be used to manage the job.

Parameter targetSelection : Specifies whether the job will continue to run (CONTINUOUS), or will be complete after all those things specified as targets have completed the job (SNAPSHOT). If continuous, the job may also be run on a thing when a change is detected in a target. For example, a job will run on a thing when the thing is added to a target group, even after the job was completed by all things originally in the group.

Parameter timeoutConfig : Specifies the amount of time each device has to finish its execution of the job. The timer is started when the job execution status is set to IN_PROGRESS. If the job execution status is not set to another terminal state before the time expires, it will be automatically set to TIMED_OUT.

Implementation

Future<CreateJobResponse> createJob({
  required String jobId,
  required List<String> targets,
  AbortConfig? abortConfig,
  String? description,
  String? document,
  String? documentSource,
  JobExecutionsRolloutConfig? jobExecutionsRolloutConfig,
  String? namespaceId,
  PresignedUrlConfig? presignedUrlConfig,
  List<Tag>? tags,
  TargetSelection? targetSelection,
  TimeoutConfig? timeoutConfig,
}) async {
  ArgumentError.checkNotNull(jobId, 'jobId');
  _s.validateStringLength(
    'jobId',
    jobId,
    1,
    64,
    isRequired: true,
  );
  ArgumentError.checkNotNull(targets, 'targets');
  _s.validateStringLength(
    'description',
    description,
    0,
    2028,
  );
  _s.validateStringLength(
    'document',
    document,
    0,
    32768,
  );
  _s.validateStringLength(
    'documentSource',
    documentSource,
    1,
    1350,
  );
  _s.validateStringLength(
    'namespaceId',
    namespaceId,
    1,
    64,
  );
  final $payload = <String, dynamic>{
    'targets': targets,
    if (abortConfig != null) 'abortConfig': abortConfig,
    if (description != null) 'description': description,
    if (document != null) 'document': document,
    if (documentSource != null) 'documentSource': documentSource,
    if (jobExecutionsRolloutConfig != null)
      'jobExecutionsRolloutConfig': jobExecutionsRolloutConfig,
    if (namespaceId != null) 'namespaceId': namespaceId,
    if (presignedUrlConfig != null) 'presignedUrlConfig': presignedUrlConfig,
    if (tags != null) 'tags': tags,
    if (targetSelection != null) 'targetSelection': targetSelection.toValue(),
    if (timeoutConfig != null) 'timeoutConfig': timeoutConfig,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'PUT',
    requestUri: '/jobs/${Uri.encodeComponent(jobId)}',
    exceptionFnMap: _exceptionFns,
  );
  return CreateJobResponse.fromJson(response);
}