Job

Class

Jobs represent long running processing tasks running on ArcGIS Services. Typically these represent complex analysis tasks such as geoprocessing tasks, logistics analysis such as fleet routing or spatial analysis tasks.

To create a Job, use the Job.submitJob method which will return an instance of the Job class with a unique id.

If you have an existing job you can use Job.serialize and Job.deserialize to save job information as a string and recreate the job to get results later.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
import { Job,  JOB_STATUSES  } from "@esri/arcgis-rest-request";

const job  = async Job.submitJob(options);

// will automatically wait for job completion and get results when the job is finished.
job.getAllResults().then((results) => {console.log(results)})

// watch for all status updates
job.on("status", ({jobStatus}) => {console.log(job.status)})

By default event monitoring is started when you call Job.waitForCompletion, Job.getAllResults or, Job.getResult and stops automatically when those promises complete. Use Job.startEventMonitoring and Job.stopEventMonitoring to manually start and stop event monitoring outside those methods. Starting monitoring with Job.startEventMonitoring will not stop monitoring when Job.waitForCompletion, Job.getAllResults or, Job.getResult complete.

Constructors

constructor

Class Constructor
new Job(optionsIJobOptions): Job
Parameters
ParameterType
options
IJobOptions
Returns 
Job

Properties

PropertyTypeNotes

Authentication manager or access token to use for all job requests.

string

The job id indicating the specific job.

string

The base URL of the job.

authentication

Class Property
authentication: string | IAuthenticationManager

Authentication manager or access token to use for all job requests.

id

Class Property
id: string

The job id indicating the specific job.

url

Class Property
url: string

The base URL of the job.

Accessors

AccessorReturnsNotes
boolean

Returns true if the job is polling for status changes.

number

The rate at which event monitoring is occurring in milliseconds.

isMonitoring

Class Accessor
get isMonitoring(): boolean

Returns true if the job is polling for status changes.

Returns 
boolean

pollingRate

Class Accessor
get pollingRate(): number

The rate at which event monitoring is occurring in milliseconds.

Returns 
number

Methods

MethodReturnsNotes
Promise<any>

Cancels the job request and voids the job.

Promise<any>

Gets all the results from a successful job by ordering all the result paramUrl requests and calling each of them until all of them are complete and returns an object with all the results.

Promise<IJobInfo>

Retrieves the status of the current job.

getResult(result)
Promise<any>

Get the specific results of a successful job by result name. To get all results see Job.getAllResults.

off(eventName, handler)
void

A handler that will remove a listener after its emitted and returns a custom handler.

on(eventName, handler)
void

A handler that listens for an eventName and returns custom handler.

once(eventName, handler)
void

A handler that listens for an event once and returns a custom handler.

string

Converts the Job to a JSON string. You can rehydrate the state of the Job with Job.deserialize.

void

Starts the event polling if the user enables the startMonitoring param.

void

Stops the event polling rate. This is can only be enabled if the user calls this method directly.

Formats the requestOptions to JSON format.

Promise<IJobInfo>

Checks for job status and if the job status is successful it resolves the job information. Otherwise will throw a ArcGISJobError if it encounters a cancelled or failure status in the job.

deserialize(serializeString, options?)
Promise<Job>
Promise<Job>

Creates a new instance of Job from an existing job id.

submitJob(requestOptions)
Promise<Job>

Submits a job request that will return a new instance of Job.

cancelJob

Class Method
cancelJob(): Promise<any>

Cancels the job request and voids the job.

Returns 
Promise<any>

An object that has job id, job status and messages array sequencing the status of the cancellation being submitted and completed.

getAllResults

Class Method
getAllResults(): Promise<any>

Gets all the results from a successful job by ordering all the result paramUrl requests and calling each of them until all of them are complete and returns an object with all the results.

If monitoring is disabled it will be enabled until the job classes resolves or rejects this promise.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
Job.submitJob(options)
 .then((job) => {
   return job.getAllResults();
 }).then(allResults => {
   console.log(allResults);
 }).catch(e => {
   if(e.name === "ArcGISJobError") {
     console.log("Something went wrong while running the job", e.jobInfo);
   }
 })

Will throw a ArcGISJobError if it encounters a cancelled or failure status in the job.

Returns 
Promise<any>

An object representing all the results from a job.

getJobInfo

Class Method
getJobInfo(): Promise<IJobInfo>

Retrieves the status of the current job.

Returns 
Promise<IJobInfo>

An object with the job id and jobStatus.

getResult

Class Method
getResult(resultstring): Promise<any>

Get the specific results of a successful job by result name. To get all results see Job.getAllResults.

If monitoring is disabled it will be enabled until the job classes resolves or rejects this promise.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
Job.submitJob(options)
 .then((job) => {
   return job.getResult("result_name")
 }).then(result => {
   console.log(result);
 }).catch(e => {
   if(e.name === "ArcGISJobError") {
     console.log("Something went wrong while running the job", e.jobInfo);
   }
 })

Will throw a ArcGISJobError if it encounters a cancelled or failure status in the job.

Parameters
ParameterTypeNotes
result
string

The name of the result that you want to retrieve.

Returns 
Promise<any>

An object representing the individual result of the job.

off

Class Method
off(eventNamestring, handler(eIJobInfo) => void): void

A handler that will remove a listener after its emitted and returns a custom handler.

Parameters
ParameterTypeNotes
eventName
string

A string of what event to listen for.

handler
(eIJobInfo) => void

A function of what to do when eventName was called.

Returns 
void

on

Class Method
on(eventNamestring, handler(eIJobInfo) => void): void

A handler that listens for an eventName and returns custom handler.

Parameters
ParameterTypeNotes
eventName
string

A string of what event to listen for.

handler
(eIJobInfo) => void

A function of what to do when eventName was called.

Returns 
void

once

Class Method
once(eventNamestring, handler(eIJobInfo) => void): void

A handler that listens for an event once and returns a custom handler.

Parameters
ParameterTypeNotes
eventName
string

A string of what event to listen for.

handler
(eIJobInfo) => void

A function of what to do when eventName was called.

Returns 
void

serialize

Class Method
serialize(): string

Converts the Job to a JSON string. You can rehydrate the state of the Job with Job.deserialize.

Returns 
string

A JSON string representing the Job.

startEventMonitoring

Class Method
startEventMonitoring(pollingRatenumber): void

Starts the event polling if the user enables the startMonitoring param.

Parameters
ParameterTypeDefaultNotes
pollingRate
number
...

Able to pass in a specific number or will default to 5000.

Returns 
void

stopEventMonitoring

Class Method
stopEventMonitoring(): void

Stops the event polling rate. This is can only be enabled if the user calls this method directly.

Returns 
void

toJSON

Class Method
toJSON(): IJobOptions

Formats the requestOptions to JSON format.

Returns 
IJobOptions

The Job as a plain JavaScript object.

waitForCompletion

Class Method
waitForCompletion(): Promise<IJobInfo>

Checks for job status and if the job status is successful it resolves the job information. Otherwise will throw a ArcGISJobError if it encounters a cancelled or failure status in the job.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
Job.submitJob(options)
 .then((job) => {
   return job.waitForCompletion();
 })
.then((jobInfo) => {
   console.log("job finished", e.jobInfo);
 })
.catch(e => {
   if(e.name === "ArcGISJobError") {
     console.log("Something went wrong while running the job", e.jobInfo);
   }
 })
Returns 
Promise<IJobInfo>

An object with a successful job status, id, and results.

deserialize

static
Class Method
deserialize(serializeStringstring, options?IJobOptions): Promise<Job>
Parameters
ParameterType
serializeString
string
options
IJobOptions
Returns 
Promise<Job>

fromExistingJob

static
Class Method
fromExistingJob(optionsIJobOptions): Promise<Job>

Creates a new instance of Job from an existing job id.

Parameters
ParameterTypeNotes
options
IJobOptions

Requires request endpoint url and id from an existing job id.

Returns 
Promise<Job>

An new instance of Job class with options.

submitJob

static
Class Method
submitJob(requestOptionsISubmitJobOptions): Promise<Job>

Submits a job request that will return a new instance of Job.

Parameters
ParameterTypeNotes
requestOptions
ISubmitJobOptions

Requires url and params from requestOptions.

Returns 
Promise<Job>

An new instance of Job class with the returned job id from submitJob request and requestOptions;

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.