Is it bad practice to do automatic notification (email/sms/etc) as part of an api call? Or should that be separated from the core functionality.
Say I update a project status and want to send notification to all users watching the project.
Can I do that from the update call or should I break it out into some other notification mechanism? Any thoughts? If doing it from the call I guess each relevant method would need an option of skipping sending notifications.
I would add to a response by Rafael Mueller that there is a difference between RESTful interface and implementation mechanics.
As far as RESTful interface is concerned here are my thoughts. Let's say you update a project status with "PUT /project/123/status". Whether email is going to be send or not it's up to a value proposition of your app. May be that's how you want to differentiate yourself from your competitors.
Let's say you support sending of emails but you want to give control to a client on a call-by-call basis. I would go with an optional HTTP Header or an optional attribute of the request body be it JSON or XML or anything else.
Once you allowed variability in emailing project status, I would advice to design a designated end-point to trigger email update on demand. Something like "POST /project/123/status/send-email". This way your client won't shoot itself in a foot: if they forgot to send email during a project status update, or simply changed their mind, they can always call "send-email".
I would rise an event, ProjectUpdated, you can add it to your messaging system (a database could solve, or rabbitmq, msmq...) and the consumer of this event, will send the email.
Related
I am dealing with a Private caller case where the Privacy header is only passed in the initial INVITE but not in the subsequent mid-dialog requests (e.g. CANCEL).
When the Privacy header is present, my downstream expects me to send them another header.
For the most part, I was able to deal with this by using dlg module to keep track of state within dialog so that the mid-dialog requests will know about the Privacy header's presence in initial INVITE.
However, a problem i have is that just for the CANCEL request, I am unable to add any headers to the SIP request relayed to downstream.
I've read in other posts (dated years back) that an option would be to use stateless CANCELs downstream. Another potential option would be to start a new transaction at my level.
I am wondering if there are other alterantives to this. I would've recommended my downstream to use $avp but it seems like even though initial INVITE and the CANCEL are supposed to be in same transaction, the $avp value stored in initial INVITE is not accessible by the CANCEL.
There are other tricks that can work. Such as using the Record-Route as a data store (that can be security issue) or asking downstream to use dlg module, which can be a big performance cost to the,.
I am wonder if any of you have solved this problem already.
Instead of dialog module , i prefer that using htable to store transaction until get ACK. It is faster than it . After getting ACK , stored transaction can be removed.
In addition , You can look at TM module and TMX module that has features about Cancel.
At this moment I'm calling a #future method X from the Account_after_update trigger. I have to use #future annotation because X makes an external site call (just to notify account is updated). It's working fine.
But for some reasons (please don't ask why) I have to remove #future annotation.
And of course it will be impossible to make HTTP request from the X method (Salesforce restriction).
Is there a way how to notify external site about account updating (and send an account ID) without using of #furure annotation? Or even without a trigger? Probably something like subscription to account_updated event.
You can use outbound messages which can send a soap request to an endpoint using workflow, or you can use the streaming api where you can create push topics to send push notifications to subscribers. Of the two options outbound messages is simplest if your endpoint supports soap.
You can try creating background jobs to do the work for you. hope you find the solution here
I am developing a small REST API. As I got into analyzing all the possible failure scenarios, which I have to handle to create a reliable and stable system, I went into thinking about how to make my APIs atomic.
If we take a simple case of creating a contact through the POST API.
The server gets the POST request for the new contact.
Creates the contact in the DB.
Creates a response to send back to the client.
The server crashes before sending the response.
The client gets a timeout error (or connection refused?)
The client is bound to think that the contact creation has failed, though, in fact, the contact was in the DB.
Is this a rare case we can ignore? How do big companies deal with such an issue?
To handle this, you should make your write APIs idempotent i.e. If the same operation is executed multiple times, the result should be same as the operation was done only once.
To achieve this in your current example, you need to be able to identify a contact uniquely based on some parameter, say emailAddress. So, if the createContact is called again with the same emailAddress, check in the DB if a contact already exists with the emailAddress. If so, return the existing contact. Else, create a new contact with the emailAddress and return it.
Hope this helps.
If the request times out, the client should not make any assumption about whether it failed or succeeded.
If it is just a user making a request from a web form, then the timeout should just be exposed to the user, and they can hit the back button and check whether the operation succeeded or not, and if not they submit the request again. (This is fine as long as you always keep a consistent state. If your operation has multiple steps and fails mid way, you need to roll back.)
However if reliable messaging is important to your application you will have to use a library or build your own reliable messaging layer. This could work by having the client assign a unique ID to every request, and having another request that lets you check the result of that request ID later. Then you can do automated retries but only where necessary.
So say a website has been updated, or some such statistic was put in (by a third party). Now, if I wanted to get this statistic sent to my phone (and this wasn't an option on the website), what would I do?
My first inclination would be to check if this site has a public API to pull information from. If that is so, you could make a server application that polls the API and sends you the data through an sms service like twillio.
I think this would be the most simple and straightforward approach.
I need solution for the following:
1) Customer places order
2) Store owner recieves email WITHOUT price info (e.g. packing list)
What files do I need to edit (I've read lots of posts and they don't seem to mention the file paths).
Thx
Two possible ways to achieve that:
You can create a model rewrite for the class Mage_Sales_Model_Order and override the function Mage_Sales_Model_Order::sendNewOrderEmail by sending an email to the shop owner using a different template
You can set the configuration entry "Sales Email/Order/Send Order Email Copy To" to nothing (so that the shop owner doesn't get the same email as the customer), and implement an observer catching the event sales_order_place_after. In the observer function you implement sending of an email to the shop owner using a template without the price info.
I know I had a hack for it ... and then I don't have it anymore. I went through everything I could and right now, we're CCing ourselves the customer notification email. As soon as we're done with our site upgrade, I'll have to readd my hack. I'm pretty sure it's in app/core/Mage/Sales/Model/Order.php possibly in public function sendNewOrderEmail()
See this pic:
I remember hard coding in a file after the customer notification was sent, we sent another one to admin but hard coding the template ID for the transactional order notification email to 8. Now, somehow, I'm doing it the "right way" but have no idea how I'm triggering this transactional email to ALSO happen with the customer order notification.
Make your custom module in that module just send a event after "sales_order_save_after".
Catch this event in observer file and put your custum coding on observer.
Read this