AWS CDK Autoscale group LifecycleHook does not notify on initial startup - aws-cdk

I have wired up an lifecycle hook to an ec2 autoscale group for both launching and terminating actions. The notification is supposed to go SNS topic that then triggers a lambda. On first startup of the autoscaling group (going from 0 to 1 instance), I only receive notification with event = "autoscaling:TEST_NOTIFICATION". I do not receive the expected launch event. However, if I terminate an instance and allow the autoscaling group to recreate the ec2 instance, the launch event fires perfectly (same for the termination event).
Is it expected that the initial scale up would not generate an event? If not, any suggestions on how I can troubleshoot this? I don't see anything in any logs that might point to the problem.

Related

What happens when link and monitor the same process in Erlang

If process A link to B and A monitor B, when B dies, what happens to A? will A receive two messages? one is monitor 'Down' message and the other is exit message from B, if it is, what's the order abd what will A do?
When links and monitors are triggered they send out signals - you can read about this in more detail here: https://www.erlang.org/doc/reference_manual/processes.html#signals
Looking at the BEAM emulator code, it turns out that the links are triggered before the monitors when a process dies - see erl_process.c: https://github.com/erlang/otp/blob/master/erts/emulator/beam/erl_process.c#L14149
I can't seem to find this fact documented anywhere, but I would guess it's to ensure that if process A doesn't trap exits, it gets killed immediately when the exit signal from process B arrives. If it got the monitor signal first, it might start acting on it but then get killed halfway through the action when the exit signal is received.

UNNotificationAction Handler on Low Power Mode

I am using Local Notifications with UNNotificationAction, when the user triggers the action I need to send an API request to the server.
When the device is on Low power mode and Background App Refresh is turned off and the app is killed, I get a weird behaviour on the action handler.
After the user taps the selected action on the notification - App Delegate didFinishLaunchingWithOptions() start to process but never finish.
It seems like the process is suspended in the middle of this function.
This behaviour also stops the handler function of the Notification Action.
After monitoring with logs (debugging from Xcode it always works), I see the state of the application is background on startup.
Also, I could not see any logs that indicate crush or process suspension
I could not find any documentation of handling such a case.
This is quite a long shot, and I don't know if it will solve your issue, but remember that there are limitations regarding what can you do inside the didFinishLaunchingWithOptions method. IIRC, if that method takes more than 10 seconds to execute, the application gets killed (the system thinks something went reeeally ballistic). So, if you need to trigger something heavy through that method, make sure you run it asynchronously.

NewRelic - monitoring process

Any idea if we can monitor a particular process in NewRelic whether it's running or not running?
I see that once we get to the detail of the server, we can see each process's status but my exact requirement is to get notification if the process in the server is running or not.
Use Newrelic Infrastructure option
After you add it to your server:
enter Infrastructure menu
Goto settings -> Alerts and add alert:
select process running alert type and the process you want to monitor
choose Trigger an alert when no processes are running
add policy with your email to get notify

Is there an alternative to JobScheduler in iOS?

In Android there is JobScheduler where you can schedule to execute part of your code (service) when conditions are met. For example, if one wants to synchronise data, he can schedule a task when there is network connection available and the phone is charging. The service will be called even if the app is never opened after phone restart.
Is there a way how to do this in iOS? For example, how dropbox, onedrive, etc. uploads pictures to the cloud even when the app is not opened after a restart?
I am not sure if what you are asking for is possible: launching an scheduler event though the app has not been launch after phone restart.
Anyway, this library could be a solution for background synchronization tasks: https://github.com/linkedin/Selene and here a complete guide: https://engineering.linkedin.com/ios/introducing-selene-open-source-library-scheduling-tasks-ios
Have a look at SwiftQueue to see if it meets your needs.
https://github.com/lucas34/SwiftQueue
SwiftQueue is a job scheduler for iOS inspired by popular android
libraries like android-priority-jobqueue or android-job. It allows you
to run your tasks with run and retry constraints.
Features
Sequential execution
Concurrent run
Persistence
Cancel all, by id or by tag
Delay
Deadline
Internet constraint
Single instance in queue
Retry: Max count, exponential backoff
Periodic: Max run, interval delay
Start / Stop queue
They also have a Battery charging constraint that's not listed in the features above.

Suggtestions for sending e-mail notifications from a 2 tier application with client potentially not connected to the internet

I have to add e-mail notifications to a client server application.
Notifications happen as the user do some particular action on the client UI.
If I had a middle tier or a service running at server I can imagine how to do it:
1) I simply create a DB tables with "pending notifications"
2) as a user does an action that generates a notification I add a record to the table
3) serverside I would continuously try to send those mails and removing them from the table once sending is succesful
Now I cannot do this now, I have a plan to add a service later on, but for now I must go the quick and dirty way.
So somehow what I was thinking to is to implement something like this:
1) as a notify-worth event occurs at client, the same client (my exe) tries to send the notification, upon failure it will log the notification in the "pending notifications" table (failure can be becuase lack of internet connection or any other problem)
2) I add a Timer that will work from any client machine to check for pending notifications. If there are any the client will try to send the e-mail (using a transaction: I will mark a field as "TryngToSendFromClientX" and in case of failure I will reset that field to NULL)
I think this approach would work, it has obvious limitations (if after failure no one logs into the system, no notification will be sent - same would be if service goes "down"). But can you comment on this approach and suggest a better one?
Additional notes (to better understand the scenario):
a) Note: all notifications are sent from the same e-mail account.
b) I don't need to keep track of who sent the e-mail.
c) the problem of creating the service now is that it will basically complicate significantly deployment and I need to create tools for monitoring the status of the service. Something that I will do in future but not now, in future I have plan to add more functionality (not only sending notifications) to the service, so in that case it makes more sense to create it.
d) I will send e-mails by using Indy components and SMTP server.
If you are not willing to create the service now, I think you are stuck with the scenario you describe. There are some things though you could do to circumvent the problem of no user firing up the client anymore while there are still pending messages.
You could add a commandline utility (or commandline parameter as bepe4711 suggested) that will only check for pending messages and try to send them.
Add this commandline utility to the StartUp folder or Run key in the registry. This way messages will at least get sent when the computer restarts, even if the user does not fire up the your app.
Add a scheduled task to run this utility at least once every day. The scheduled task can be added by code or by your installer.
If you do both, you will only have to worry about pending messages of users that never start their computer again.
Perhaps you can add a parameter to your client which causes it to just look at the pending notifications and send them. After this it can terminate itself. It will just act like some kind of service.
Then you install the client on the server and start it every x minutes.
I do something very similar to the approach you describe. Instead of sending emails I need to call a web service. My application is installed on several laptops and they are commonly not connected to any network.
When my application raises an exception I collect various bits of information including user comments and screen shots. Then I attempt to send this to our web service. If by chance the web service is not available. (i.e. not connected to the internet or web service is down) I write the results to an XML file on disk in the User Profile (App_Data) directory.
The one major difference is I don't poll to check to see if the server is up. I attempt to send them again on the startup of the application.
If both Systems are running on Windows, have a look at MS Message Queue. It is designed to send notifications to systems, which are not allways online. I did it in .Net, there are already easy to use classes implemented. Not sure about Delphi.
Latest version of Windows uses much more the Windows Task Scheduler, and now task can be fired on event (i.e. when a network card gets connected...). You could write a separate utility that tries to send pending notification, even if noone is logged in.

Resources