def create_job_request():
    job = JobRequest()
    job.job_id = "sample_cloud_to_device_method"
    job.type = "cloudToDeviceMethod"
    job.start_time = ""
    job.max_execution_time_in_seconds = 60
    job.update_twin = ""
    job.query_condition = ""
    return job
Exemplo n.º 2
0
def create_twin_update_job_request():
    job = JobRequest()
    job.job_id = "twinjob-" + str(uuid.uuid4())
    job.type = "scheduleUpdateTwin"
    job.start_time = datetime.datetime.utcnow().isoformat()
    job.update_twin = Twin(
        etag="*", properties=TwinProperties(desired={"temperature": 98.6}))
    job.query_condition = "*"
    return job
def create_method_job_request():
    job = JobRequest()
    job.job_id = "methodJob-" + str(uuid.uuid4())
    job.type = "scheduleDeviceMethod"
    job.cloud_to_device_method = CloudToDeviceMethod(
        method_name="test_method",
        payload={"key": "value"},
        response_timeout_in_seconds=30,
        connect_timeout_in_seconds=15,
    )
    job.start_time = datetime.datetime.utcnow().isoformat()
    job.max_execution_time_in_seconds = 60
    job.query_condition = "*"
    return job
    def test_iot_hub_job_manager_jobs(self):
        try:
            iothub_job_manager = IoTHubJobManager(iothub_connection_str)

            # Create job request
            job_id = "sample_cloud_to_device_method"
            job_type = "cloudToDeviceMethod"
            job_execution_time_max = 60
            job_request = JobRequest()
            job_request.job_id = job_id
            job_request.type = job_type
            job_request.start_time = ""
            job_request.max_execution_time_in_seconds = job_execution_time_max
            job_request.update_twin = ""
            job_request.query_condition = ""

            new_job_response = iothub_job_manager.create_job(
                job_request.job_id, job_request)

            # Verify result
            assert new_job_response.job_id == job_type
            assert new_job_response.type == job_type
            assert new_job_response.max_execution_time_in_seconds == job_execution_time_max

            # Get job
            get_job = iothub_job_manager.get_job(new_job_response.job_id)

            # Verify result
            assert get_job.job_id == job_id
            assert get_job.type == job_type
            assert get_job.max_execution_time_in_seconds == job_execution_time_max

            # Cancel job
            iothub_job_manager.cancel_job(get_job.job_id)

        except Exception as e:
            logging.exception(e)