Skip to content

Commit

Permalink
retry longhaul Device Method due to SAS refresh (#1794)
Browse files Browse the repository at this point in the history
* retry longhaul Device Method due to SAS refresh

* made rety a loop
  • Loading branch information
ericwolz authored Dec 15, 2020
1 parent c219a67 commit 9d3ad48
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1388,15 +1388,27 @@ static int invoke_device_method(const void* context)
device_method_info.method_id = method_id;
device_method_info.time_invoked = time(NULL);

if ((device_method_info.method_result = IoTHubDeviceMethod_Invoke(
iotHubLonghaul->iotHubSvcDevMethodHandle,
iotHubLonghaul->deviceInfo->deviceId,
LONGHAUL_DEVICE_METHOD_NAME,
message,
MAX_DEVICE_METHOD_TRAVEL_TIME_SECS,
&responseStatus, &responsePayload, &responseSize)) != IOTHUB_DEVICE_METHOD_OK)
for (int i = 0; i < 2; i++)
{
LogError("Failed invoking device method");
device_method_info.method_result = IoTHubDeviceMethod_Invoke(
iotHubLonghaul->iotHubSvcDevMethodHandle,
iotHubLonghaul->deviceInfo->deviceId,
LONGHAUL_DEVICE_METHOD_NAME,
message,
MAX_DEVICE_METHOD_TRAVEL_TIME_SECS,
&responseStatus, &responsePayload, &responseSize);

if (device_method_info.method_result == IOTHUB_DEVICE_METHOD_OK || responseStatus != 404)
{
break;
}

ThreadAPI_Sleep(1000 * 60); // wait for the SAS reconnect and try again
}

if (device_method_info.method_result != IOTHUB_DEVICE_METHOD_OK)
{
LogError("Failed invoking device method with status %d", responseStatus);
}

if (iothub_client_statistics_add_device_method_info(iotHubLonghaul->iotHubClientStats, DEVICE_METHOD_INVOKED, &device_method_info) != 0)
Expand Down

0 comments on commit 9d3ad48

Please sign in to comment.