JobClient class
Provides methods to create, update, monitor and cancel long-running jobs on an IoT Hub instance, as well as query existing jobs. The Jobs API in Azure IoT Hub allows to schedule direct method calls and twin updates on multiple devices.
SDK users are expected to create JobClient instances using the factory methods fromConnectionString(string) and fromSharedAccessSignature(string).
function cancelJob(jobId: string | number): Promise<JobStatusResponse>
Parameters
- jobId
-
string | number
Returns
Promise<JobStatusResponse>
Cancels an existing job.
function cancelJob(jobId: string | number, done?: TripleValueCallback<any, any>)
Parameters
- jobId
-
string | number
The identifier of an existing job.
- done
-
TripleValueCallback<any, any>
The optional function to call when the operation is
complete. done
will be called with three
arguments: an Error object (can be null), a
job object, and a transport-specific response
object useful for logging or debugging.
Creates a query that can be used to return pages of existing job based on type and status.
function createQuery(jobType?: JobType, jobStatus?: JobStatus, pageSize?: number): Query
Parameters
- jobType
-
JobType
The type that should be used to filter results.
- jobStatus
-
JobStatus
The status that should be used to filter results.
- pageSize
-
number
The number of elements to return per page.
Returns
Query
Constructs a JobClient object from the given connection string.
static function fromConnectionString(connectionString: string): JobClient
Parameters
- connectionString
-
string
A connection string which encapsulates the appropriate (read and/or write) Registry permissions.
Returns
Constructs a JobClient object from the given shared access signature.
static function fromSharedAccessSignature(sharedAccessSignature: string): JobClient
Parameters
- sharedAccessSignature
-
string
A shared access signature which encapsulates the appropriate (read and/or write) Registry permissions.
Returns
Constructs a JobClient object from the given shared Azure TokenCredential.
static function fromTokenCredential(hostName: string, tokenCredential: TokenCredential): JobClient
Parameters
- hostName
-
string
Host name of the Azure service.
- tokenCredential
- TokenCredential
An Azure TokenCredential used to authenticate with the Azure service
Returns
function getJob(jobId: string | number): Promise<JobStatusResponse>
Parameters
- jobId
-
string | number
Returns
Promise<JobStatusResponse>
Requests information about an existing job.
function getJob(jobId: string | number, done?: TripleValueCallback<any, any>)
Parameters
- jobId
-
string | number
The identifier of an existing job.
- done
-
TripleValueCallback<any, any>
The optional function to call when the operation is
complete. done
will be called with three
arguments: an Error object (can be null), a
job object, and a transport-specific response
object useful for logging or debugging.
function scheduleDeviceMethod(jobId: string | number, queryCondition: string, methodParams: DeviceMethodParams): Promise<JobStatusResponse>
Parameters
- jobId
-
string | number
- queryCondition
-
string
- methodParams
- DeviceMethodParams
Returns
Promise<JobStatusResponse>
function scheduleDeviceMethod(jobId: string | number, queryCondition: string, methodParams: DeviceMethodParams, jobStartTime: Date): Promise<JobStatusResponse>
Parameters
- jobId
-
string | number
- queryCondition
-
string
- methodParams
- DeviceMethodParams
- jobStartTime
-
Date
Returns
Promise<JobStatusResponse>
function scheduleDeviceMethod(jobId: string | number, queryCondition: string, methodParams: DeviceMethodParams, jobStartTime: Date, maxExecutionTimeInSeconds: number): Promise<JobStatusResponse>
Parameters
- jobId
-
string | number
- queryCondition
-
string
- methodParams
- DeviceMethodParams
- jobStartTime
-
Date
- maxExecutionTimeInSeconds
-
number
Returns
Promise<JobStatusResponse>
scheduleDeviceMethod(string | number, string, DeviceMethodParams, Date, number, TripleValueCallback<any, any>)
Schedules a job that will execute a device method on a set of devices.
function scheduleDeviceMethod(jobId: string | number, queryCondition: string, methodParams: DeviceMethodParams, jobStartTime?: Date, maxExecutionTimeInSeconds?: number, done?: TripleValueCallback<any, any>)
Parameters
- jobId
-
string | number
The unique identifier that should be used for this job.
- queryCondition
-
string
A SQL query WHERE clause used to compute the list of devices on which this job should be run.
- methodParams
- DeviceMethodParams
An object describing the method and shall have the following properties: - methodName The name of the method that shall be invoked. - payload [optional] The payload to use for the method call. - responseTimeoutInSeconds [optional] The number of seconds IoT Hub shall wait for the device
- jobStartTime
-
Date
Time time at which the job should start
- maxExecutionTimeInSeconds
-
number
The maximum time alloted for this job to run in seconds.
- done
-
TripleValueCallback<any, any>
The optional function to call when the operation is
complete. done
will be called with three
arguments: an Error object (can be null), a
job object, and a transport-specific response
object useful for logging or debugging.
scheduleDeviceMethod(string | number, string, DeviceMethodParams, Date, TripleValueCallback<any, any>)
function scheduleDeviceMethod(jobId: string | number, queryCondition: string, methodParams: DeviceMethodParams, jobStartTime: Date, done: TripleValueCallback<any, any>)
Parameters
- jobId
-
string | number
- queryCondition
-
string
- methodParams
- DeviceMethodParams
- jobStartTime
-
Date
- done
-
TripleValueCallback<any, any>
function scheduleDeviceMethod(jobId: string | number, queryCondition: string, methodParams: DeviceMethodParams, done: TripleValueCallback<any, any>)
Parameters
- jobId
-
string | number
- queryCondition
-
string
- methodParams
- DeviceMethodParams
- done
-
TripleValueCallback<any, any>
function scheduleTwinUpdate(jobId: string | number, queryCondition: string, patch: any): Promise<JobStatusResponse>
Parameters
- jobId
-
string | number
- queryCondition
-
string
- patch
-
any
Returns
Promise<JobStatusResponse>
function scheduleTwinUpdate(jobId: string | number, queryCondition: string, patch: any, jobStartTime: Date): Promise<JobStatusResponse>
Parameters
- jobId
-
string | number
- queryCondition
-
string
- patch
-
any
- jobStartTime
-
Date
Returns
Promise<JobStatusResponse>
function scheduleTwinUpdate(jobId: string | number, queryCondition: string, patch: any, jobStartTime: Date, maxExecutionTimeInSeconds?: number): Promise<JobStatusResponse>
Parameters
- jobId
-
string | number
- queryCondition
-
string
- patch
-
any
- jobStartTime
-
Date
- maxExecutionTimeInSeconds
-
number
Returns
Promise<JobStatusResponse>
Schedule a job that will update a set of twins with the patch provided as a parameter.
function scheduleTwinUpdate(jobId: string | number, queryCondition: string, patch: any, jobStartTime?: Date, maxExecutionTimeInSeconds?: number, done?: TripleValueCallback<any, any>)
Parameters
- jobId
-
string | number
The unique identifier that should be used for this job.
- queryCondition
-
string
A SQL query WHERE clause used to compute the list of devices on which this job should be run.
- patch
-
any
The twin patch that should be applied to the twins.
- jobStartTime
-
Date
Time time at which the job should start
- maxExecutionTimeInSeconds
-
number
The maximum time alloted for this job to run in seconds.
- done
-
TripleValueCallback<any, any>
The optional function to call when the operation is
complete. done
will be called with three
arguments: an Error object (can be null), a
job object, and a transport-specific response
object useful for logging or debugging.
function scheduleTwinUpdate(jobId: string | number, queryCondition: string, patch: any, jobStartTime: Date, done: TripleValueCallback<any, any>)
Parameters
- jobId
-
string | number
- queryCondition
-
string
- patch
-
any
- jobStartTime
-
Date
- done
-
TripleValueCallback<any, any>
function scheduleTwinUpdate(jobId: string | number, queryCondition: string, patch: any, done: TripleValueCallback<any, any>)
Parameters
- jobId
-
string | number
- queryCondition
-
string
- patch
-
any
- done
-
TripleValueCallback<any, any>