Intercept all webjob method/function calls - azure-webjobs

Is there a way to intercept a WebJob function call? I'd like to wrap it once rather than littering my code base (a dozen projects and hundreds of triggers) with repeated code to analyze the function call.
I'm familiar with IJobActivator, and am looking for something similar with regards to intercepting a method/function call.

Is there a way to intercept a WebJob function call?
You could use Function Filters which allow you to encapsulate common logic to be shared across many different functions.
Currently it supports two filter type: Invocation Filters and Exception Filters.
The Invocation Filters have both Executing and Executed methods that are called immediately before and immediately after the target job function is invoked.
You could apply filters globally by adding filters to the JobHostConfiguration service collection with following code:
var extensions = config.GetService<IExtensionRegistry>();
extensions.RegisterExtension<IFunctionInvocationFilter>(myFilter);
For more details, you could read this wiki to learn.

Related

how to read/write a value from/in the context object cdk step functions

I am writing in AWS CDK a Step Function which run two tasks in parallel. I would like to access from one of the tasks , a value of the second tasks , which runs in parallel (for example, I would like to know in task 1, which is the time started task 2, or maybe id from task 2).
Here an screenshot of the state machine definition in Step Function.
In the example of the screenshot, I would like to use the Id of the GlueStartRunJob (1) in GlueStartRunJob.
I was thinking about using the Context Object for that purpose. Nevertheless, I am not sure if this is the right approach...
The Context Object is read-only and allows a give state to access contextual information about it's self, not about other states from elsewhere in the workflow.
I'm not 100% clear what you are aiming to accomplish here, but I can see a couple of possible approaches.
First, you might just want to order these Glue Jobs to run sequentially so the output from the first can be used in the second.
Second, if you need the workflow to take action after the Glue Jobs have started but before they have completed, you'd need to take an approach that does not use the .sync integration pattern. With this integration pattern, Step Functions puts a synchronous facade over an asynchronous interaction, taking care of the steps to track completion and return you the results. You could instead use the default RequestResponse pattern to start the jobs in your parallel state, then do whatever you needed to after. You'd need to then include your own polling logic if you wanted the workflow to wait for completion of the jobs and return data on them or take action on completion. You can see an example of such polling for Glue Crawlers in this blog post (for which you can find sample code here).

Map XML to a custom C/C++ function

I come from an Android development background and I would like to know if there's a way to allow XML to execute a C/C++ method? This is similar to Android's onClick event where a method is executed when a event has been received i.e. a button press, but I just want the XML to map and execute the method.
Thanks
In general, no. For example, there is no way to make an XSLT document execute a C++ method.
There are some systems (.Net and XAML spring to mind, but I believe Android is similar), where a dialect of XML is used to define a GUI, and attributes or elements define the functions to be called. This works better in a language with reflection, where the engine reading the XML can directly call the functions, but with something like GetProcAddress or dlsym you could make it work.

High level PHP library for Amazon SWF deciders to check state of activity tasks

I'm writing PHP for fairly simple workflow for Amazon SWF. I've found myself starting to write a library to check if certain actions have been started or completed. Essentially looping over the event list to check how things have progressed, and then starting an appropriate activity if its needed. This can be a bit faffy at times as the activity type and input information isn't in every event, it seems to be in the ActivityTaskScheduled event. This sort of thing I've discovered along the way, and I'm concerned that I could be missing subtle things about event lists.
It makes me suspect that someone must have already written some sort of generic library for finding the current state of various activities. Maybe even some sort of more declarative way of coding up the flowcharts that are associated with SWF. Does anything like this exist for PHP?
(Googling hasn't come up with anything)
I'm not aware of anything out there that does what you want, but you are doing it right. What you're talking about is coding up the decider, which necessarily has to look at the entire execution state (basically loop through the event list) and decide what to do next.
Here's an example written in python
( Using Amazon SWF To communicate between servers )
that looks for events of type 'ActivityTaskCompleted' to then decide what to do next, and then, yes, looks at the previous 'ActivityTaskScheduled' entry to figure out what the attributes for the previous task were.
If you write a php framework that specifies the workflow in a declarative way then a generic decider that implements it, please consider sharing it :)
I've since found https://github.com/cbalan/aws-swf-fluent-php which looks promising, but not really used it, so can't speak to the whether it works or not.
I've forked it and started a bit of very light refactoring to allow some testing, available at https://github.com/michalc/aws-swf-fluent-php

How to monitor communication in a SOA environment with an intermediary?

I'm looking for a possiblity to monitor all messages in a SOA enviroment with an intermediary, who'll be designed to enforce different rule-sets over the message's structure and sequences (e.g., let's say it'll check and ensure that Service A has to be consumed before B).
Obviously the first idea that came to mind is how WS-Adressing might help here, but I'm not sure if it does, as I don't really see any mechanism there to ensure that a message will get delivered via a given intermediary (as it is in WS-Routing, which is an outdated proprietary protocol by Microsoft).
Or maybe there's even a different approach that the monitor wouldn't be part of the route but would be notified on request/responses, which might it then again make somehow harder to actively enforce rules.
I'm looking forward to any suggestions.
You can implement a "service firewall" either by intercepting all the calls in each service as part of your basic servicehost. Alternatively you can use 3rd party solutions and route all your service calls to them (they will do the intercepting and then forward calls to your services).
You can use ESBs to do the routing (and intercepting) or you can use dedicated solutions like IBM's datapower, XML firewall from Layer7 etc.
For all my (technical) services I use messaging and the command processor pattern, which I describe here, without actually calling the pattern name though. I send a message and the framework finds to corresponding class that implements the interface that corresponds to my message. I can create multiple classes that can handle my message, or a single class that handles a multitude of messages. In the article these are classes implementing the IHandleMessages interface.
Either way, as long as I can create multiple classes implementing this interface, and they are all called, I can easily add auditing without adding this logic to my business logic or anything. Just add an additional implementation for every single message, or enhance the framework so it also accepts IHandleMessages implementations. That class can than audit every single message and store all of them centrally.
After doing that, you can find out more information about the messages and the flow. For example, if you put into the header information of your WCF/MSMQ message where it came from and perhaps some unique identifier for that single message, you can track the flow over various components.
NServiceBus also has this functionality for auditing and the team is working on additional tooling for this, called ServiceInsight.
Hope this helps.

Is there a C++ or Qt library available to measure feature use of an application

I would like to be able to measure the features in our application that are being used.
For example how much certain windows are opened, certain controls are clicked.
I can imagine a tool that measures this and sends a report to a web server, that can further process it to create meaningful data from it
First question : should you do it ? People don't like when their software phones home without their consent. But assuming they are ok with it then:
It's technically possible, with two approaches: automatic or manual. Of course, given your question, I assume that you are using Qt.
Automatic:
give a proper name to all the QObject that you want to trace
install an event filter on your application to catch all the ChildEvent about objects that are created and destroyed.
from the ChildEvent, you can extract the object's name
then you can already log how often that object is created. You can also use the opportunity to add an event listener to that specific object, to be notified when it is shown or hidden or track other kind of usage
log everything to a log file
Manual :
add log statements to relevant part of your code that you want to track.
Final :
send the log file on a regular basis
I guess, your answer is "No". I don't think there are such libraries.
I also think, the best solution here is logging, meaning you should manually introduce some log functions into your main program features and send back the log file. When it comes to logging, you may consider using aspect-oriented programming (and there are such tools for C++), it may simplify your task...