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.
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 Constructornew Job(options: IJobOptions): Job
Parameters
Parameter | Type |
---|---|
options | IJobOptions |
Returns
Job
Properties
Property | Type | Notes |
---|---|---|
string | IAuthenticationManager | 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 Propertyauthentication: string | IAuthenticationManager
Authentication manager or access token to use for all job requests.
Accessors
Accessor | Returns | Notes |
---|---|---|
get isMonitoring() | boolean | Returns |
get pollingRate() | number | The rate at which event monitoring is occurring in milliseconds. |
Methods
Method | Returns | Notes |
---|---|---|
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 |
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 | |
startEventMonitoring(pollingRate) | 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. | |
toJSON() | 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 | |
deserialize(serializeString, options?) | Promise<Job> | |
fromExistingJob(options) | Promise<Job> | Creates a new instance of |
submitJob(requestOptions) | Promise<Job> | Submits a job request that will return a new instance of |
cancelJob
Class MethodcancelJob(): 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 MethodgetAllResults(): 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.
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 MethodgetJobInfo(): Promise<IJobInfo>
Retrieves the status of the current job.
Returns
Promise<IJobInfo>
An object with the job id and jobStatus.
getResult
Class MethodgetResult(result: string): 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.
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
Parameter | Type | Notes |
---|---|---|
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 Methodoff(eventName: string, handler: (e: IJobInfo) => void): void
A handler that will remove a listener after its emitted and returns a custom handler.
Parameters
Parameter | Type | Notes |
---|---|---|
event | string | A string of what event to listen for. |
handler | (e: IJobInfo) => void | A function of what to do when eventName was called. |
Returns
void
on
Class Methodon(eventName: string, handler: (e: IJobInfo) => void): void
A handler that listens for an eventName and returns custom handler.
Parameters
Parameter | Type | Notes |
---|---|---|
event | string | A string of what event to listen for. |
handler | (e: IJobInfo) => void | A function of what to do when eventName was called. |
Returns
void
once
Class Methodonce(eventName: string, handler: (e: IJobInfo) => void): void
A handler that listens for an event once and returns a custom handler.
Parameters
Parameter | Type | Notes |
---|---|---|
event | string | A string of what event to listen for. |
handler | (e: IJobInfo) => void | A function of what to do when eventName was called. |
Returns
void
serialize
Class Methodserialize(): 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 MethodstartEventMonitoring(pollingRate: number): void
Starts the event polling if the user enables the startMonitoring param.
Parameters
Parameter | Type | Default | Notes |
---|---|---|---|
polling | number | ... | Able to pass in a specific number or will default to 5000. |
Returns
void
stopEventMonitoring
Class MethodstopEventMonitoring(): void
Stops the event polling rate. This is can only be enabled if the user calls this method directly.
Returns
void
toJSON
Class MethodtoJSON(): IJobOptions
Formats the requestOptions to JSON format.
Returns
IJobOptions
The Job
as a plain JavaScript object.
waitForCompletion
Class MethodwaitForCompletion(): 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.
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
deserialize(serializeString: string, options?: IJobOptions): Promise<Job>
Parameters
Parameter | Type |
---|---|
serialize | string |
options | IJobOptions |
Returns
Promise<Job>
fromExistingJob
fromExistingJob(options: IJobOptions): Promise<Job>
Creates a new instance of Job
from an existing job id.
Parameters
Parameter | Type | Notes |
---|---|---|
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
submitJob(requestOptions: ISubmitJobOptions): Promise<Job>
Submits a job request that will return a new instance of Job
.
Parameters
Parameter | Type | Notes |
---|---|---|
request | 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;