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 blocks Copy
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.
authentication
string | IAuthenticationManager
Authentication manager or access token to use for all job requests.
id
string
The job id indicating the specific job.
url
string
The base URL of the job.
authentication Class Propertyauthentication: string | IAuthenticationManager
Authentication manager or access token to use for all job requests.
id Class Propertyid: string
The job id indicating the specific job.
url Class Propertyurl: string
The base URL of the job.
Accessors Accessor Returns Notes get isMonitoring()
boolean
Returns true
if the job is polling for status changes.
get pollingRate()
number
The rate at which event monitoring is occurring in milliseconds.
isMonitoring Class Accessorget isMonitoring(): boolean
Returns true
if the job is polling for status changes.
boolean
pollingRate Class Accessor get pollingRate(): number
The rate at which event monitoring is occurring in milliseconds.
ReturnsÂnumber
Methods Method Returns Notes cancelJob()
Promise<any>
Cancels the job request and voids the job.
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.
getJobInfo()
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.
serialize()
string
Converts the Job
to a JSON string. You can rehydrate the state of the Job
with Job.deserialize
.
startEventMonitoring(pollingRate)
void
Starts the event polling if the user enables the startMonitoring param.
stopEventMonitoring()
void
Stops the event polling rate. This is can only be enabled if the user calls this method directly.
toJSON()
IJobOptions
Formats the requestOptions to JSON format.
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.
deserialize(serializeString,âoptions?)
Promise<Job>
fromExistingJob(options)
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(): 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.
Use dark colors for code blocks Copy
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.
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.
Use dark colors for code blocks Copy
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.
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 NoteseventName
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 Method on(eventName:Â string,âhandler:Â (e:Â IJobInfo) => void): void
A handler that listens for an eventName and returns custom handler.
Parameters Parameter Type NoteseventName
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 Method once(eventName:Â string,âhandler:Â (e:Â IJobInfo) => void): void
A handler that listens for an event once and returns a custom handler.
Parameters Parameter Type NoteseventName
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 Method serialize(): string
Converts the Job
to a JSON string. You can rehydrate the state of the Job
with Job.deserialize
.
string
A JSON string representing the Job
.
startEventMonitoring(pollingRate:Â number): void
Starts the event polling if the user enables the startMonitoring param.
Parameters Parameter Type Default NotespollingRate
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(): 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 blocks Copy
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.
deserializestatic
Class Methoddeserialize(serializeString:Â string,âoptions?:Â IJobOptions): Promise<Job>
Parameters Parameter Type serializeString
string options
IJobOptions Returns Promise<Job>
fromExistingJob
static
Class MethodfromExistingJob(options:Â IJobOptions): Promise<Job>
Creates a new instance of Job
from an existing job id.
options
IJobOptions
Requires request endpoint url and id from an existing job id.
ReturnsÂPromise<Job>
An new instance of Job class with options.
submitJobstatic
Class MethodsubmitJob(requestOptions:Â ISubmitJobOptions): Promise<Job>
Submits a job request that will return a new instance of Job
.
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;
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4