Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.13k stars 3.77k forks source link

Invoke-AzContainerInstanceCommand - Script not stopping after successful command #16854

Open obayesshelton opened 2 years ago

obayesshelton commented 2 years ago

Description

Hi,

I am running RunBook Version 7.1 and the latest ContainerInstance modules. The script runs fine and I can see the commands being executed on the container instance. However the script never stops. My script is as followed:

# Ensures you do not inherit an AzContext in your runbook
Disable-AzContextAutosave -Scope Process

# Connect to Azure with system-assigned managed identity
$AzureContext = (Connect-AzAccount -Identity).context

# set and store context
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext   

Invoke-AzContainerInstanceCommand -ContainerGroupName byob-feature-product-engine -ContainerName byob-feature-product-engine-one -ResourceGroupName DevApplication -Command "npm run script_eod_daily_equity_prices"

Is seems as though the Invoke-AzContainerInstanceCommand isn't returning a success code or something for the script to know it has finished.

Issue script & Debug output

Mode             : Process
ContextDirectory : 
ContextFile      : 
CacheDirectory   : 
CacheFile        : 
Settings         : {}

> byobeta@1.0.0 script_eod_daily_equity_prices
> python -c 'from etl.tasks import *; process_eod_daily_equity_prices()'

Getting Price for:BGFD.LSE
ETLException, BGFD.LSE , Cannot find EOD Price for:BGFD.LSE
Getting Price for:BDEV.LSE
ETLException, BDEV.LSE , Cannot find EOD Price for:BDEV.LSE
Getting Price for:BWY.LSE
ETLException, BWY.LSE , Cannot find EOD Price for:BWY.LSE
Getting Price for:VTY.LSE
ETLException, VTY.LSE , Cannot find EOD Price for:VTY.LSE
Getting Price for:GNS.LSE
ETLException, GNS.LSE , Cannot find EOD Price for:GNS.LSE
Getting Price for:AV.LSE
ETLException, AV.LSE , Cannot find EOD Price for:AV.LSE
Getting Price for:DGE.LSE
ETLException, DGE.LSE , Cannot find EOD Price for:DGE.LSE
Getting Price for:BDEV.LSE
ETLException, BDEV.LSE , Cannot find EOD Price for:BDEV.LSE
Getting Price for:HLMA.LSE
ETLException, HLMA.LSE , Cannot find EOD Price for:HLMA.LSE
Getting Price for:HNE.LSE
ETLException, HNE.LSE , Cannot find EOD Price for:HNE.LSE
Getting Price for:LGEN.LSE
ETLException, LGEN.LSE , Cannot find EOD Price for:LGEN.LSE
Getting Price for:BRWM.LSE
ETLException, BRWM.LSE , Cannot find EOD Price for:BRWM.LSE
Getting Price for:SCP.LSE
ETLException, SCP.LSE , Cannot find EOD Price for:SCP.LSE
Getting Price for:OXT.LSE
ETLException, OXT.LSE , Cannot find EOD Price for:OXT.LSE
Getting Price for:OXIG.LSE
ETLException, OXIG.LSE , Cannot find EOD Price for:OXIG.LSE
Getting Price for:PSN.LSE
ETLException, PSN.LSE , Cannot find EOD Price for:PSN.LSE
Getting Price for:UTG.LSE
ETLException, UTG.LSE , Cannot find EOD Price for:UTG.LSE
Getting Price for:PRU.LSE
ETLException, PRU.LSE , Cannot find EOD Price for:PRU.LSE
Getting Price for:LIO.LSE
ETLException, LIO.LSE , Cannot find EOD Price for:LIO.LSE
Getting Price for:SSE.LSE
ETLException, SSE.LSE , Cannot find EOD Price for:SSE.LSE
Getting Price for:SRP.LSE
ETLException, SRP.LSE , Cannot find EOD Price for:SRP.LSE
Getting Price for:MGNS.LSE
ETLException, MGNS.LSE , Cannot find EOD Price for:MGNS.LSE
Getting Price for:LLOY.LSE
ETLException, LLOY.LSE , Cannot find EOD Price for:LLOY.LSE
Equity - Daily Prices Saved: 0/23 :-1:
Equity - Daily Prices Not Found: 23 :-1:
Equity - Missing Daily Prices: BGFD.LSE BDEV.LSE BWY.LSE VTY.LSE GNS.LSE AV.LSE DGE.LSE BDEV.LSE HLMA.LSE HNE.LSE LGEN.LSE BRWM.LSE SCP.LSE OXT.LSE OXIG.LSE PSN.LSE UTG.LSE PRU.LSE LIO.LSE SSE.LSE SRP.LSE MGNS.LSE LLOY.LSE
:white_check_mark: Background task: Process EOD Daily Equity Prices For Products V2

Environment data

N/A

Module versions

Az.ContainerInstance
3.0.0
7.1 (preview)

Error output

N/A
dingmeng-xue commented 2 years ago

@BethanyZhou , please help to look into it.

BethanyZhou commented 2 years ago

Hi @obayesshelton ,

Could you check your command or script whether terminates on your local environment? Seems like your script is under python interactive mode. For non-terminating case, we will look forward to user's next input or Ctrl-C.

obayesshelton commented 2 years ago

Hi @BethanyZhou

When using Powershell via terminal on my Apple laptop the output is as followed and it does terminate fine

PS /Users/oliver/Projects/byobeta> Invoke-AzContainerInstanceCommand -ContainerGroupName byob-feature-product-engine -ContainerName byob-feature-product-engine-one -ResourceGroupName DevApplication -Command "npm run script_eod_daily_equity_prices"

> byobeta@1.0.0 script_eod_daily_equity_prices
> python -c 'from etl.tasks import *; process_eod_daily_equity_prices()'

Getting Price for:BGFD.LSE
https://eodhistoricaldata.com/api/eod/BGFD.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:BDEV.LSE
https://eodhistoricaldata.com/api/eod/BDEV.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:BWY.LSE
https://eodhistoricaldata.com/api/eod/BWY.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:VTY.LSE
https://eodhistoricaldata.com/api/eod/VTY.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:GNS.LSE
https://eodhistoricaldata.com/api/eod/GNS.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:AV.LSE
https://eodhistoricaldata.com/api/eod/AV.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:DGE.LSE
https://eodhistoricaldata.com/api/eod/DGE.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:BDEV.LSE
https://eodhistoricaldata.com/api/eod/BDEV.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:HLMA.LSE
https://eodhistoricaldata.com/api/eod/HLMA.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:HNE.LSE
https://eodhistoricaldata.com/api/eod/HNE.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:LGEN.LSE
https://eodhistoricaldata.com/api/eod/LGEN.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:BRWM.LSE
https://eodhistoricaldata.com/api/eod/BRWM.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:SCP.LSE
https://eodhistoricaldata.com/api/eod/SCP.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:OXT.LSE
https://eodhistoricaldata.com/api/eod/OXT.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
ETLException, OXT.LSE , Cannot find EOD Price for:OXT.LSE
Getting Price for:OXIG.LSE
https://eodhistoricaldata.com/api/eod/OXIG.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:PSN.LSE
https://eodhistoricaldata.com/api/eod/PSN.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:UTG.LSE
https://eodhistoricaldata.com/api/eod/UTG.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:PRU.LSE
https://eodhistoricaldata.com/api/eod/PRU.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:LIO.LSE
https://eodhistoricaldata.com/api/eod/LIO.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:SSE.LSE
https://eodhistoricaldata.com/api/eod/SSE.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:SRP.LSE
https://eodhistoricaldata.com/api/eod/SRP.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:MGNS.LSE
https://eodhistoricaldata.com/api/eod/MGNS.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Getting Price for:LLOY.LSE
https://eodhistoricaldata.com/api/eod/LLOY.LSE?from=2022-01-18&to=2022-01-19&period=d&api_token=6156d42b6df943.72036216&fmt=json
Equity - Daily Prices Saved: 22/23 :-1:
Equity - Daily Prices Not Found: 1 :-1:
Equity - Missing Daily Prices: OXT.LSE
:white_check_mark: Background task: Process EOD Daily Equity Prices For Products V2
PS /Users/oliver/Projects/byobeta> 

Is there some sort of response we could return via the script for Invoke-AzContainerInstanceCommand to end?

At the moment I have to stop the Runbook job daily which isn't the end of the world but it is not clean.

BethanyZhou commented 2 years ago

Thank you @obayesshelton for your information.

At the moment I have to stop the Runbook job daily which isn't the end of the world but it is not clean.

Is there some sort of response we could return via the script for Invoke-AzContainerInstanceCommand to end?

obayesshelton commented 2 years ago

Hey @BethanyZhou as per the other ticket. This doesn't work.

The script finishes and completes as I can see things in the database etc but PowerShell doesn't know it has completed.

dingmeng-xue commented 2 years ago

Adjust it to feature request because it requires additional implementation. We will check how API of PowerShell can handle it.

jucabot commented 2 years ago

Same issue; the runbook with Invoke script appears in the test pane as running forever

BethanyZhou commented 2 years ago

@obayesshelton @jucabot how about adding exit() at the end of python command like "python -c 'from etl.tasks import *; process_eod_daily_equity_prices();exit()'"?

Please let me know if it works. If not, I guess I have to find an expert in runbook for help.

baldwicc commented 2 years ago

Seeing the same issue in PowerShell7 runbooks using Az.ContainerInstance v3.1.0

Here's a test runbook that stays Running forever in a sleep-ing debian:bullseye container:

Write-Output "Connecting to Azure with MSI..."
Connect-AzAccount -Identity -ErrorAction Stop | Format-Table
$resourceGroupName = Get-AzResourceGroup | Select-Object -ExpandProperty ResourceGroupName

$acg = Get-AzContainerGroup -Name $containerGroupName -ResourceGroupName $resourceGroupName

Invoke-AzContainerInstanceCommand                       `
    -ResourceGroupName $acg.ResourceGroupName       `
    -ContainerGroupName $acg.Name                   `
    -ContainerName $acg.Container[0].Name           `
    -Command '/bin/echo "hello"'
obayesshelton commented 2 years ago

@BethanyZhou didn't fix the issue. It also seems now things are running twice.

Not going to lie but this is the worse feature in the entire Azure library.

BethanyZhou commented 2 years ago

@obayesshelton , @baldwicc, @jucabot , To clear the environment, did you meet this issue on Azure Automation Runbooks 7.1?

obayesshelton commented 2 years ago

On both @BethanyZhou