Skip to main content
SUBMITTED

Launch a job manually outside of the desktop app

  • December 15, 2023
  • 8 replies
  • 60 views

rvgfox
Problem Solver
Forum|alt.badge.img+4

I need an option to give to my users the possibility to launch a job manually outside of the desktop app.

We have some jobs scheduled but some times the user (some key users) needs to launch the job manually before the time that it’s schedule.

 

Some ideas to how to do it?

 

8 replies

Thomas Lind
Community Manager
Forum|alt.badge.img+5
  • Community Manager
  • December 15, 2023

Hi @rvgfox 

This feature does not exist for the SaaS release.

You can for LTS where there is a specific feature for this.

I have converted this to a feature request.


rory.smith
TimeXtender Xpert
Forum|alt.badge.img+8
  • TimeXtender Xpert
  • December 15, 2023

Hi,

is the API not an option? 

 

You can simply trigger a job from Powershell and monitor its progress...


Thomas Lind
Community Manager
Forum|alt.badge.img+5
  • Community Manager
  • December 15, 2023

Hi @rory.smith 

Sure you can run a post command against the TX API, but compared to before where we had a program where you could force an execution with a button in a tool we do not have it.

I guess an updated version of the tool that sends these sort of API requests or adding a button in the portal that could start a package would be what I thought of.


rory.smith
TimeXtender Xpert
Forum|alt.badge.img+8
  • TimeXtender Xpert
  • December 15, 2023

Hi Thomas,

 

true. I guess that makes for a great addition.

You could also use Exmon I guess, but for a practical work-around using the API should be OK.


anders.e.jonsson
Contributor
Forum|alt.badge.img+1

Hi,

I have used simple Powershell scripts to start jobs using the API. Some of them with conditions and schedules.
That’s quite easy.

BR
Anders


rvgfox
Problem Solver
Forum|alt.badge.img+4
  • Author
  • Problem Solver
  • December 19, 2023

@anders.e.jonsson Can you share some example from how to call the API from PowerShell?


anders.e.jonsson
Contributor
Forum|alt.badge.img+1

Hi,

Here is a sample. Sorry about the comments in Swedish 😁. I’ll try to find time to translate.

The script starts by checking for a trigger value in a database.
If the value is 1, the the job is triggered.
After that the trigger value is reset to 0.

But I think that all you need to run a job are the marked lines. You have to change the xxx for api key and job id respectively.

#Skript som startar jobb i TimXtender om ett värde finns i databastabell - 20231019
#Skapa lite variabler
$servername="server"
$databasename="db"
#$User=""
#$Pwd=""
$tablename="TxRefreshTrigger"
$columnname="TxNewDataArrived"
$triggervalue="1"
$Resetvalue="0"

# Define the SQL query to retrieve data from the table
$query = "SELECT $columnName FROM $tableName"

try {
    # Skapa query och läs första raden (finns bara en)
    $result = Invoke-SqlCmd -ServerInstance $serverName -Database $databaseName -Query $query
    #$result = Invoke-SqlCmd -ServerInstance $serverName -Database $databaseName -Username $User -Password $Pwd -Query $query
    $columnvalue = $result.$columnName
    #Endast för test  Write-Host $columnvalue
}
catch {
    Write-Host "An error occurred: $_"
}
#Endast för testWrite-Host $columnvalue #Endast för test
#Kolla om ny data kommit in. I så fall hämtar vi ny data och återställer kolumnens värde till 0
if ($columnvalue -eq $triggervalue)
{
    #URL med endpoint
    $apikey="XXXXXXXXX"
    $apiUrl="https://apim-txportal-prod.azure-api.net/public/jobs/xxxxxxxxxxx/execute"
    #Headers
    $headers=@{
        "ApiKey"="$apikey"
        "Content-Type" = "application/json"
    }
    #Skicka api request
    $response=Invoke-RestMethod -Uri $apiUrl -Headers $headers -Method POST
    #Endast för test Read-Host #Endast för test
    $UpdateQuery="Update $tablename SET $columnname=$Resetvalue;"
    Invoke-SqlCmd -ServerInstance $servername -Database $databasename -Query $UpdateQuery
    #Invoke-SqlCmd -ServerInstance $servername -Database $databasename -Username $User -Password $Pwd -Query $UpdateQuery
    #Endast för test  Write-Host "Nu har vi läst in data och ändrat till 0" 
}
else
{
    #Endast för test  Write-Host "Inget har hänt" #Endast för test
}

 

A bit crude and basic, but it does it’s job 😊

 

BR

Anders


rvgfox
Problem Solver
Forum|alt.badge.img+4
  • Author
  • Problem Solver
  • December 19, 2023

Thanks @anders.e.jonsson I will test it.

Here is translated:

#Script that starts jobs in TimXtender if a value is in database table - 20231019
#Create some variables
$servername="server"
$databasename="db"
#$User=""
#$Pwd=""
$tablename="TxRefreshTrigger"
$columnname="TxNewDataArrived"
$triggervalue="1"
$Resetvalue="0"

# Define the SQL query to retrieve data from the table
$query = "SELECT $columnName FROM $tableName"

try {
# Create query and read first line (there is only one)
$result = Invoke-SqlCmd -ServerInstance $serverName -Database $databaseName -Query $query
#$result = Invoke-SqlCmd -ServerInstance $serverName -Database $databaseName -Username $User -Password $Pwd -Query $query
$columnvalue = $result.$columnName
#Only for test Write-Host $columnvalue
}
catch {
Write-Host "An error occurred: $_"
}
#Only for testWrite-Host $columnvalue #Only for test
#Check if new data came in. If so, we retrieve new data and reset the column value to 0.
if ($columnvalue -eq $triggervalue)
{
#URL med endpoint
$apikey="XXXXXXXXX"
$apiUrl="https://apim-txportal-prod.azure-api.net/public/jobs/xxxxxxxxxxx/execute"
#Headers
$headers=@{
"ApiKey"="$apikey"
"Content-Type" = "application/json"
}
#Send api request
$response=Invoke-RestMethod -Uri $apiUrl -Headers $headers -Method POST
#Only for testing Read-Host #Only for testing
$UpdateQuery="Update $tablename SET $columnname=$Resetvalue;"
Invoke-SqlCmd -ServerInstance $servername -Database $databasename -Query $UpdateQuery
#Invoke-SqlCmd -ServerInstance $servername -Database $databasename -Username $User -Password $Pwd -Query $UpdateQuery
#Only for test Write-Host "Now we have read the data and changed to 0"
}
else
{
#Only for testing Write-Host "Nothing happened" #Only for testing
}