How is it that we can't access RetryContext on the ExecutionContext on a Azure Function?
try
{
//my code here....
}
catch (Exception ex)
{
if (executionContext.RetryContext?.RetryCount)
}
The RetryContext property is not there? WTF?!
Please check the below steps if it helps to fix the issue:
In .NET 6 Azure Functions (v4), RetryContext is available as part of FunctionContext/ExecutionContext as given in this MS Doc.
It can be accessible using the Namespace Microsoft.Azure.Functions.Worker.
The Same Property RetryContext is part of the ExecutionContext when it comes to non-dotnet languages as given in the GitHub Repos of Azure Functions Host Retry Context include proposal.
Related
I'm working on exploring the following 2 features of Azure App Configuration in Azure Function's Http Trigger
Externalizing the App Settings
Feature Flags
Below is how i'm getting the reference of the configuration
So, when I use _configuration["SomeAppSettingKey"], I'm able to retrieve the value. So, I'm able to achieve #1 feature mentioned above.
My Question is, How do we retrieve the Feature Flag information? I have tried the below ways.
I would appreciate if someone could help me in understanding how to retrieve it in Azure Functions (I'm using V3)? A Sample code or any reference to documentation would be helpful.
Thanks.
Update1:
I can deserialize the json content as shown below. But, is this is the right approach?
Where FeatureManager is a class that I have defined as shown below.
all you need is to call UseFeatureFlags() function as part of AddAzureAppConfiguration to let the App Configuration provider know you want to use feature flags. An example can be found following the link below. It uses the FunctionsStartup and dependency injection (DI) of Azure Functions. An instance of a feature manager is put into the DI.
https://github.com/Azure/AppConfiguration/blob/master/examples/DotNetCore/AzureFunction/FunctionApp/Startup.cs
The link below shows how you can obtain the instance of IFeatureManagerSnapshot from DI and use it as part of your Azure Functions call.
https://github.com/Azure/AppConfiguration/blob/master/examples/DotNetCore/AzureFunction/FunctionApp/ShowBetaFeature.cs
Deserialize JSON is not a good idea, every time you will add new key you need to modify your class.
private static IConfiguration Configuration { set; get; }
static Function1()
{
var builder = new ConfigurationBuilder();
builder.AddAzureAppConfiguration(Environment.GetEnvironmentVariable("ConnectionString"));
Configuration = builder.Build();
}
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string keyName = "TestApp:Settings:Message";
string message = Configuration[keyName];
return message != null
? (ActionResult)new OkObjectResult(message)
: new BadRequestObjectResult($"Please create a key-value with the key '{keyName}' in App Configuration.");
}
We recently tried out the premium plan for our azure functions and we are noticing a lot of requests for 'admin/warmup'. My guess is that it is part of the premium plan for keeping the function workers alive, but I couldn't find any documentation on this. Anybody knows if this is the case?
That's correct!
Here's a snippet from Azure Functions HostController
[HttpGet]
[HttpPost]
[Route("admin/warmup")]
[Authorize(Policy = PolicyNames.AdminAuthLevelOrInternal)]
[RequiresRunningHost]
public async Task<IActionResult> Warmup([FromServices] IScriptJobHost scriptHost)
{
await scriptHost.TryInvokeWarmupAsync();
return Ok();
}
The changes are made recently and the docs aren't updated with that yet. You can validate the same with this git commit:
https://github.com/Azure/azure-functions-host/commit/30405116a72e90ab17e77d2c39787d2e7f6f9570
I have been learning the bot framework from microsoft and have been following a tutorial on pluralsight. I have made the changes to my Global.asax.cs and for some reason I keep on getting the error setting must be in the form name=value. I have no idea what to do and how to get rid of these errors. Any help would be highly appreciated.
Global.asax.cs
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
// This code chunk below will allow us to use table bot data store instead of
// in memory data store
Conversation.UpdateContainer(
builder =>
{
builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
// here we grab the storage container string from our web config and connecting
var store = new TableBotDataStore(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
builder.Register(c => store).
Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore).
AsSelf().
SingleInstance();
});
GlobalConfiguration.Configure(WebApiConfig.Register);
TableBotDataStore is for Azure Table Storage, and it seems you are using some sql connectionstring. You would usually have that connection string in the AppSettings section, not the ConnectionStrings section (yes, the names are a bit misguiding here).
In Visual Studio 2017 with the latest update, for azure functions template, I want something where I can initialize like program.cs in webjobs template.
I am trying to create a new subscription with new namespace Manager when application initializes so that I can listen to one service bus topic.
Is there a way to do that? If yes then how?
If you intend to create a subscription that this Function will be triggered on, there is no need to do that manually. Function App will create the subscription based on your binding at deployment time.
For other scenarios (e.g. timer-triggered function), you can do the initialization in a static constructor:
public static class MyFunction1
{
static MyFunction1()
{
var namespaceManager = NamespaceManager.CreateFromConnectionString(connString);
if (!namespaceManager.SubscriptionExists("topic1", "subscription1"))
{
namespaceManager.CreateSubscription("topic1", "subscription1");
}
}
[FunctionName("MyFunction1")]
public static void Run(
// ...
}
Static constructor will run at the time of the first function call.
for azure functions template, I want something where I can initialize like program.cs in webjobs template.
As far as I know, Azure functions do not have good support for this right now. You can find a similar question:
Question:
I have a C# function and want to know if there is any Initialization point. I have dependency injection containers that need initialization
and want to know where to do that.
Mathew's reply
We don't have a good story for this right now. Please see open issue
here in our repo where this is discussed.
In liferay i have a requirement like if i am updating the roles of multiple users if one of them updating the role of the user is failed then i want to rollback all the updated roles of users. i have applied as follows.
#Transactional(isolation = Isolation.SERIALIZABLE,
propagation = Propagation.REQUIRES_NEW)
public int updateUserRole(long userId,long groupId,long roleId) throws SystemException{
try{
return UserTokenFinderUtil.updateUserRole(userId,groupId,roleId);
}
catch(Exception e){
System.out.println("Exception occured UserTokenServiceImpl");
e.printStackTrace();
return -1;
}
}
Can anyone help me out with fresh eyes?
The best way to do that is doing it in a custom service (i.e. ServiceBuilder) method. Something like MyCustomServiceUtil.addRoles(). Transactions are managed by Liferay in this case, and you'll get the expected result.
This should be handled by default by service builder.
for that you should be using LocalServiceImpl class rather than *Util class
The entry point to transaction in Liferay is the *LocalServiceImpl class.
DML operations update, insert and delete on one Entity from another do not use calls to LocalServiceUtil or LocalService as this will result in two transaction boundaries.
You can refer to below Link for more infor.
Transaction Management with liferay service