When the StockService are directly using the CartAccessor.Cart.OrderCarrier and that method is only working if the execution is in a web request with session state enabled.
If you should execute this from the search indexing you need to set the website and country on the StockStatusCalculatorArgs from something else.
if (discontinued)
{
_stockStatusCalculator.GetStockStatuses(new StockStatusCalculatorArgs
{
WebSiteSystemId = channel.WebsiteSystemId,
CountrySystemId = channel.CountryLinks.FirstOrDefault().CountrySystemId
}, new StockStatusCalculatorItemArgs
{
VariantSystemId = variant.SystemId,
Quantity = 1
}).TryGetValue(variant.SystemId, out var stockStatus);
//if stock status is not returned or the actual stock level is zero or below.
return (stockStatus?.InStockQuantity.GetValueOrDefault(0) ?? -1) < 1;
}