0 votes

I am setting up a custom script to do a remote web call (HTTP post) using Invoke-Webrequest.

I have it working, but how can I have Adaxes send an email or retry if the remote HTTP server is down or unreachable during the attempted call?

This is the error that would be output from a failed attempt in this case.

Unable to connect to the remote server. For example:

Invoke-WebRequest -URI someunreachable.com

The site has to have a valid DNS name obviously, but let's assume the site does but it is just unreachable for some reason (network, web services down, etc)

by (320 points)

1 Answer

0 votes
by (3.6k points)

Hello,

To send e-mail messages from scripts executed in Adaxes, you can use the SendMail method of the predefined $Context variable. To retry a web request for a certain number of attempts or until it is successful, you can use the following script. In the script:

$waitTimeInterval – specifies how many seconds will the script wait before the next attempt.

$retryCount – specifies the maximum number of attempts.

$waitTimeInterval = 5 # TODO: modify me
$retryCount = 10 # TODO: modify me

do
{
    try
    { 
        $response = Invoke-WebRequest -Uri "http://host.domain.com"
    }
    catch
    {
        $retryCount--
        Start-Sleep -Seconds $waitTimeInterval
    }
}
while ($response.StatusCode -ne 200 -and $retryCount -gt 0)

Please note, that by default, the timeout for PowerShell script execution in Adaxes is 10 minutes. For detailed information, please see https://www.adaxes.com/help/?ManageBusinessRules.IncreaseScriptTimeout.html.

Related questions

0 votes
1 answer

Hi, Is there anyway to get a listing of the currently running jobs? If not, feature request :) Also, when you update the web portal, one feature requested by some of ... (in IE), so users sometimes press multiple times thinking it has failed to run. regards

asked Jun 19, 2013 by firegoblin (1.6k points)
0 votes
1 answer

Hi, I was just wondering if there was a way to force the format of the date picker value in the web approval interface. We have operation that are very time specific ... like that in the web interface. Example of the problem: Thank you, Jean-Simon Tremblay

asked Dec 3, 2021 by jsimon.tremblay (20 points)
0 votes
1 answer

I'm currently receiving the below error when trying to remove or add actions to a web interface's homepage. I only get the error on this specific dashboard, others are ... the web interface there. I'm currently running Adaxes version 2021.1 if that helps

asked May 21, 2021 by richarddewis (260 points)
0 votes
1 answer

Hi all, I have a condition during new user creation - Where the corporate email is entered into the email address field, but a custom drop-down for "Mailbox required?" is No. ... screen, and be able to save the result of this choice to a variable? Thanks all,

asked Oct 24 by dshortall (80 points)
0 votes
1 answer

We try to use ADSI scripting to automate some tasks using Adaxes 2023. One such task is to try to check whether an answer provided by a user to his question is correct or not. ... . But I do not see an easy way to do this using ADSI script and/or interfaces.

asked Oct 22 by gfang (20 points)
3,550 questions
3,241 answers
8,236 comments
547,827 users