Job

interface Job<T> : JsonSerializable

A job is a long-running asynchronous operation performed by an ArcGIS Server asynchronous service operation.

This is the base class for a range of long-running jobs classes, such as GeoprocessingJob, GenerateGeodatabaseJob, com.arcgismaps.tasks.geodatabase.SyncGeodatabaseJob, GenerateOfflineMapJob, and ExportVectorTilesJob. You can create a job instance from its associated task using a set of parameters. For example, to create a GeoprocessingJob, call com.arcgismaps.tasks.geoprocessing.GeoprocessingTask.createJob and provide a set of com.arcgismaps.tasks.geoprocessing.GeoprocessingParameters. A newly instantiated job has a status of JobStatus.NotStarted.

Call Job.start to initiate the job on the server. If the server accepts the job, it assigns a unique job id (available from the Job.serverJobId) and executes the job. At this point, the job status is JobStatus.Started. The running job periodically polls the server to get messages and progress of the job. While the job is in progress, you can listen for changes to the Job.status, display its collection of Job.messages, and report the Job.progress to show the percentage of the job that has been completed.

When the job is done, you can examine the Job.status to determine if it was successful. If the job failed (JobStatus.Failed), information about the failure is available in the Job.messages. If the job succeeds (JobStatus.Succeeded), its specific type of result is returned. For example, a successful GeoprocessingJob returns a com.arcgismaps.tasks.geoprocessing.GeoprocessingResult, a successful ExportVectorTilesJob returns an com.arcgismaps.tasks.exportvectortiles.ExportVectorTilesResult, and so on.

If necessary, you can pause a job and re-start it using Job.pause and Job.start, respectively. Note, you should always cancel jobs that are no longer needed by calling Job.cancel. This sends a cancel request to the server and helps reduce unnecessary server load.

Since

200.0.0

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val messages: SharedFlow<JobMessage>

The job's messages. Indicates that a new JobMessage was generated.

Link copied to clipboard
abstract val progress: StateFlow<Int>

The current progress of the job as a percentage complete. This emits updates when the progress value changes.

Link copied to clipboard
abstract val serverJobId: String

The server job Id of the job.

Link copied to clipboard
abstract val status: StateFlow<JobStatus>

The status of the job.

Functions

Link copied to clipboard
abstract suspend fun cancel(): Result<Boolean>

Cancels this Job and waits for any asynchronous, server-side operations to be canceled. The job is canceled and will result in a JobStatus.Failed status after all cancellation tasks have completed. For jobs running on a server, a cancel request is sent for the associated Job.serverJobId. You should always cancel unneeded jobs (for example when exiting your app) to avoid placing unnecessary load on the server. Examples of server-side jobs include:

Link copied to clipboard
abstract suspend fun checkStatus(): Result<Boolean>

Initiates a request to check the server status. If the job is polling the server for status and is in a time gap, then calling this method will ensure a request is sent right away. The result can be false if the job is not checking server status for example if the job status is paused or uploading.

Link copied to clipboard
abstract fun pause(): Boolean

Pauses the job.

Link copied to clipboard
abstract suspend fun result(): Result<T>

Suspends until this job has completed. Calling this function does not start the job. In order to start the job call start

Link copied to clipboard
abstract fun start(): Boolean

Starts executing the job if the job is not started or paused.

Inherited functions

Link copied to clipboard
abstract fun toJson(): String

Convert an object to JSON string.