Update 'MaxConcurrentActivityFunctions' for a durable task once it's published - azure-durable-functions

I have a function app with a durable task running on Azure. What is the best way of changing the 'MaxConcurrentActivityFunctions' binding (i.e. in host.json) once it's been deployed/published?
"extensions": {
"durableTask": {
"MaxConcurrentActivityFunctions": 4, // ensures scale-out for mappers
}
}
I want to change it to 1 or 4 depending on the type of service plan I use.
I haven't been able to find a way to do it with the Azure SDK, or with a rest api. The only way I can think of getting it to work is to stop the function app, download the host.json file, modify it, upload it, and restart the function app.
Seems like overkill to me. Am I missing something?

host.json uses the aspnet core config system.
You can set an app setting (environment variable) AzureFunctionsJobHost__extensions__durableTask__MaxConcurrentActivityFunctions=1 through the portal (or Azure ARM REST APIs) and it should take precedence over the value in host.json

Related

Azure Function ServiceBus Trigger Dependency Injection

I have been trying to implement DI for Azure Functions where the functions is triggered by ServiceBus (topics/subscriptions in this case):
[Singleton]
[FunctionName("Alert")]
public static async Task Alert([ServiceBusTrigger(Topic.Alert, Subscription.PowerBi, Connection = "servicebusconnectionstring")] Message message, [Inject]IPowerBiService powerBiService, [Inject]IQueueService queueService)
I have read about Azure Functions and DI on following sites:
https://mcguirev10.com/2018/04/03/service-locator-azure-functions-v2.html
https://blog.wille-zone.de/post/azure-functions-proper-dependency-injection/
https://github.com/introtocomputerscience/azure-function-autofac-dependency-injection
All examples works fins using HTTP trigger, I assume the IIS host is up and running and is containing the services. But using ServiceBus trigger, I can't get it to work. I have implemented the solutions mention above, and a few more but all get same issues. The code works, bu the services are created for message/trigger.
Anyone out there that has manage to do this, or arn't it possible to do?
NOTE (update):
I got some more information that I haven’t got time to verify yet, but I have been using a consumption plan for my Azure Functions. It may be the case that you need an App Service Plan instead (using consumption since that price model is more convenient). If anyone know more about this?
I will look into this later this week.
I just want to confirm that it work’s fine now using an App Service Plan instead of an Consumption Plan. The difference is the "cold start" instead of a "warm" host.
I guess all different once of DI implementations should work fine.
I have been using following : https://github.com/MV10/Azure.FunctionsV2.Service.Locator

Share constants between iOS client code and Parse cloud code

I have an iOS app that uses Parse as backend. There, some cloud code is executed.
Both have to share the same constants.
I can share these constants on the client side via obj-c #import, and I can share it on the cloud code side via module.exports / require.
But how can I share it between client code and cloud code? It is simply error prone to define the same constants twice.
Parse offers a config object that can be queried like a class (returning an NSDictionary in iOS). Moreover, it can be configured via the web UI at parse.com. See docs here.
Upon startup, your app can retrieve the config and cache it locally. You may choose to cache it semi-permanently (say, with NSUserDefaults) and then use local copy indefinitely. I usually opt for some fixed expiration period (like weekly, so my constants are not-quite constant). Start up logic is, if the interval between now and my last config fetch exceeds the week, fetch again and replace.

MVC scheduled mail sending

I have got an ASP.NET MVC 4 application, and I want it to send a report e-mail every week. I've read about Quartz.NET, but it's too powerful for this easy task. Now I'm trying to use NCron, but it requires an initialiser in the Main() method (with obligatory parameter args):
class Program
{
static void Main(string[] args)
{
Bootstrap.Init(args, ServiceSetup);
}
}
Is there the way to do this in the Application_Start()? What should I pass as a args param? What other solutions can solve this task?
Author of NCron speaking…
First: I have never myself integrated NCron into a web application, and I am not sure how well it will work. For instance, as Kenneth points out, IIS will shut down your app if it does not receive any traffic, and there might be other hiccups as well.
In order to integrate NCron into a web app, I suggest that you ignore Bootstrap.Init() (designed specifically as an entry point to console apps) and rather work directly with SchedulingService:
using (var service = new SchedulingService())
{
service.Hourly().Run<DataUpdateJob>();
service.Daily().Run<RecycleCacheJob>();
service.Start();
}
Again: I have never done this myself, but please do give it a try, and let me and everyone else know how you fare.
You'll have to look up what ncrone does with those parameters. What this does is pass the command-line arguments of your windows app to the component.
If you're using it on a web app, you don't have command-line args so if it needs arguments, you will have to construct the arguments yourself (either hard-coded or from a config-file or a database or ...)
It's also possible that these are optional, then you can just pass in an empty array (but again, check the docs of ncrone)
Also, keep in mind that when your application shuts down (standard that is after 20 minutes without any activity), your cron runner will not wake it up. If that will be the case you either need to keep the application alive by assuring that at least one request is done every 20 minutes or configure IIS to keep it alive always.

How do I consume a real web service from a BPEL Process?

I've been doing some research on BPEL for about two weeks now and still don't quite get it.
I have deployed the HelloWorld sample in ODE and have also managed to deploy this other one.
My intention was to do something like the second example but with my own real WS deployed and working.
I'm now at the point of having a process with no errors and correctly deployed in ODE with the following structure:
I have started the project from a service definition importing my Multiply.wsdl. The Designer has composed the import tag into the MuktiplyProcessArtifacts.wsdl next to the PartnerLinkTypes all automagically so I assume all namespaces, etc are ok.
There is a few concepts I misundertand in order to make all of this work:
In my original Multiply.wsdl I have
soap:address
location="http://localhost:8080/WS-multiply/multiply"
but ODE tells me my soap:address must have the form host.port/ode/processes..
This doesn't sound reasonable to me since my WS could be implemented anywhere outside my ODE_HOME.
The second example I mentioned before explains how the Designer presumably creates a "Caller.wsdl", which in fact has the function I would desire, which is to implement a "wrapper" WSDL, providing the BPEL process with entry and exit points. The issue is the Designer does not generate that interface. Am I supposed to create it myself? Do I have to create it at all?
If that 3rd wsdl is really needed, is it the one I would have to call if I wanted to test the whole process?
It looks like your partner WSDL is associated to a myrole of a partnerlink. Partnerlinks and partnerlink types are a concept in BPEL that is used to define dual interfaces in a sense that if a partner A wants to communicate with a BPEL process as a buyer, it needs to provide a certain set of functionality that the process can use for further communications (i.e. sending a shipment confirmation to the buyer). Thus, a partnerlink maintains two roles, the myRole is the portType (aka interface) that the process itself provides, the partnerRole refers to a portType the process expects to be implemented by the partner. MyRoles must be of course implemented by the BPEL process and thus needs to have an endpoint that is exposed by the BPEL engine. PartnerRoles can be bound to arbitrary endpoints. This happens in the deployment descriptor, which is the deploy.xml in ODE.
I guess you can fix your process by assigning your partner WSDL to a partner role.
I hope http://thiliniishaka.blogspot.com/2012/10/develop-ws-bpel-process-using-wso2.html
and http://thiliniishaka.blogspot.com/2012/10/part-2-developing-ws-bpel-process-using.html may help you to resolve aforementioned queries.
Thanks
Thilini
Its mandatory to have Ode.war deployed at tomcat server, tomcat create a path like the picture, you need to config your endpoit with the complete path /ode/processes
c:\apache-tomcat-7.0.55\webapps\ode\WEB-INF\processes\BPEL_WS\

Is it possible to programmatically determine if my app is running as a Windows Service? [duplicate]

How can I tell if the application my code is running in, is it in a service or an application? Why do I want to know this - I'm writing some code that is injected into the target application and that code has no way of knowing this information up front, so it has to work it out itself.
I cannot rely on any code being called from the service control manager, start, stop, or command line parameters.
I'm currently looking at GetConsoleWindow() which I hope will return NULL for a service (no console) and a window handle for any application (has a console). Not sure how valid this assumption is.
Any ideas for a better solution?
Search the current process id (GetCurrentProcessId) from the list of all running services (EnumServicesStatusEx)?
The assumption of GetConsoleWindow() is not valid.
It seems to me that you care about the context of your process more. Are you asking that if your program is running in service context or the user session? If so, use ProcessIdToSessionId() http://msdn.microsoft.com/en-us/library/aa382990%28v=VS.85%29.aspx to get your session id and you will know it.
Use WMI to query for Win32_Service instances where 'ProcessId=MyProcessid'. If there is no match, then your process is not a service.
Background on WMI app creation in C++ here.
For Windows Vista or later you can check the session id. Session 0 is reserved for services and non-interactive programs. User sessions start from 1.
Use OpenProcessToken to get the current process token. Then use CheckTokenMembership to see if the token includes the WinServiceSid well-known SID.

Resources