Backend loop, multiple thread and sessions - loops

I'm currently having some question on how some tools are working.
For a product build a test project to connect a database from notion to a twitter account in order to schedule some publication.
I will use OAuth2 and if possible nodeJs for the backend. I've seen that Zappier is doing this but I'm also curious on how to build this tool, so it's also a "improve your knowledge project" but I've some questions that I struggle with.
To retrieve notion database info I need to have a loop like:
Loop every x minutes:
- check for database update
- if there is a new tweet inside the database
- send the tweet to the twitter account related
- update the database status and add a published tag
This is globally the main action that needs to be done.
My questions are:
How can I loop to all my connected user in an effective maner?
If I have 400 users and I need to post 400 tweet with a one minute loop I think the second loop will start before the 400 requests might be sent, specially if I await for the answers.
How to not stop the loop for all my user if one error happen during the loop?
I can't really think of a solution to have one "thread/process" for each user in order for on loop to run for one user.
How can I start a new "loop" every time a new user connect, is it a good solution?
Is node js the best technology to go with?
If you know how zappier is doing it, or if you know or have already done something similar with this kind of isolation or if you know how I can "start" a new loop everytime a new customer connect to the app? any information are welcome.

Related

Handling whether or not the user has already seen a popup, ReactJS

I am a bit dumbfounded on how to achieve this properly. So you have an app that is getting regularly updated, and you show those new updates to the user (something like discord update popup and whats new and such). How do you handle whether or not the user has seen it? A more high level question that "local storage", I am well aware of that or storing it in a DB, but this doesn't seem 1) Scalable, 2) Easy to work with in the long run. Are there any JS libraries that can simplify the process, eg or do I have to manually track each update? If there are more updates or the user hasn't logged in a while
I hope I conveyed what I am working on properly. Would love to hear how it's usually done.
Q: have an app that is getting regularly updated, and you show those new updates to the user
A: Service Worker can help you .That support reacting to push message .And they provide the Push API gives web applications the ability to receive messages pushed to them from a server, whether or not the web app is in the foreground, or even currently loaded, on a user agent.
More detail about start up a service worker to send users a message . https://developer.mozilla.org/en-US/docs/Web/API/Push_API .
Finally I suggest you try Workbox , that is a library that bakes in a set of best practices when working with service workers.

Run code in GAE according to changes in Firebase

Since Parse is shutting down, we are currently using Firebase to support basic data storage and real-time messaging. However, in order to implement a key feature in our app, we need to run some code on a server. The following is what we are trying to accomplish:
We allow users to upload key words to Firebase, then we want to send notifications to them if any new posts that contain these key words were uploaded by other users. For example, userA wants to know if anyone posted information related to chemistry, so userA enters key words "chemistry" and "science" in our app which get stored in Firebase, userB posted an article called "chemistry rocks!" which contains the key word "chemistry", userA will then receive a notification immediately about this post.
We have a couple of solutions in mind, but we are not sure which way to go and how to properly implement these solutions.
1 - Build a server that listens to Firebase changes and also supports sending notifications to individual users. However, to host and maintain a server just to run a search algorithm is just too much work for this simple task.
2 - Store the key words in another database that somehow can send notifications according to the search result. This would be faster because we wouldn't have to connect Firebase server to our own server, but again we would still have to host and maintain a separate server.
I have looked into Google App Engine, their push/pull queue feature sounds like something we want, but does GAE support notifications? And also how can we hook it up with Firebase? We also came across Firebase+Batch to send notifications, but I don't think Batch supports cloud computation.
Has anyone run into this problem? Any solutions?

Integrating notifications/messages to the client in an AngularJS + ASP.NET Web API app

I'm creating a SPA application with AngularJS at the client side and ASP.NET Web API as backend. My database is SQL Server 2012. There will be users which have a favourite sports team and a simple icon in the UI displaying the number of new articles/news/comments added or whatever connected to their favourite teams.
What I'd like to achieve is the following: Whenever a record about their team is inserted (record with TeamID column value for example equal to the user's favourite team ID), that notifications count icon should be updated immediately (just like Facebook's notifications - it's updated when a friend has posted on your wall or has tagged you and so on). How can I best achieve this?
What I'm thinking of for now is just setting an interval function in AngularJS to check every 30 seconds, let's say, if there are new records in the database making a request to a Web API controller. Of course this suggests a lot of checking for when the user is logging out - when was the last check, what will be the date to check against next time he/she logs in and so on.
You can use signalR for this. It's a framework for real time communication. Check out this to get if you want to get started. It can easily be used together with angularJS.
What you are looking for is push
Sadly i never used it so i don't know much about it, but i think you should use technologies like pusher

Pulling facebook and twitter status updates into a SQL database via Coldfusion Page

I'd like to set up a coldfusion page that will pull the status updates from my own facebook account and twitter accounts and put them in a SQL database along with their timestamps. Whenever I run this page it should only grab information after the most recent time stamp it already has within the database.
I'm hoping this won't be too bad because all I'm interested in is just status updates and their time stamps. Eventually I'd like to pull other things like images and such, but for a first test just status updates is fine. Does anyone have sample code and/or pointers that could assist me in this endeavor?
I'd like it if any information relates to the current version of the apis (twitter with oAuth and facebook open graph) if they are necessary. Some solutions I've seen involve the creation of a twitter application and facebook application to interact with the APIs; is that necessary if all I want to do is access a subset of my own account information? Thanks in advance!
I would read the max(insertDate) from the database and if the API allows you, only request updates since that date. Then insert those updates. The next time you run you'll just need to get the max() of the last bunch of updates before calling for the next bunch.
You could run it every 5 minutes using a ColdFusion scheduled task.
How you communicate with the API is usually using <cfhttp />. One thing I always do is log every request and response, either in a text file, or in a database. That's can be invaluable when troubleshooting.
Hope that helps.
Use the cffeed tag to pull RSS feeds from Twitter and Facebook. Retain the date of the last feed scan somewhere (application variable or database) and loop over the feed entries. Any entry older than last scan is ignored, everything else gets committed. Make sure to wrap cffeed in a try/catch, as it will throw errors if the service is down (ahem, twitter) As mentioned in other answers, set it up as a scheduled task.
<cffeed action="read" properties="feedMetadata" query="feedQuery"
source="http://search.twitter.com/search.atom?q=+from:mytwitteraccount" />
Different approach than what you're suggesting, but it worked for us. We had two live events, where we asked people to post to a bespoke Facebook fan page, or to Twitter with a hashtag we endorsed for the event in realtime. Then we just fetched and parsed the RSS feeds of the FB page, and the Twitter search results, extracting what was new, on a short interval... I think it was approximately every three minutes. CFFEED was a little error-prone and wonky, just doing a CFHTTP get of the RSS feeds, and then processing the CFHTTP.filecontent struct item as XML worked fine
.LAG

In Silverlight programming, how to prevent visitors from caching the downloaded content?

I want to create an online quiz website using Silverlight.
When the registered users are logged in, they can view and answer the quiz once per page.
To proceed to the next question, they must push next button, and the new data downloaded from the server.
The previous questions are not cached. Thereby everytime the question is requested, the question will be reloaded from the server again.
My question is how to do my scenario above in silverlight?
Thank you in advance.
Now that your intent is clear, you want to prevent discovery of the content in your assembly. The answer is you can't really protect your assembly. In order to run it the client needs to fetch it, if it can be fetched then the would be hacker can get it, trying to limit caching isn't really a prevention.
However the solution is to not put senstive stuff in your assembly to start with. Place code server side to do the sensitive stuff and access that code via a service interface such as WCF or Web services or even plain old XML in XML out posting.
You could use IsolatedStorage to store some state related info (and you can even encrypt it before you save if you want - it's your storage, do what you want with it). Another way to store state information is to use cookies, here and here.
The "state" information that i refer to is the state and/or progress of your Silverlight app, i.e. you can track where the user got to in the questions, and avoid requesting questions they have already completed. Both of these types of storage can be deleted by the end user, if they know what they are doing. But you shouldn't let that worry you - if they want to cheat, then let them.
Create the silverlight app to request the questions via a Web Service. As long as you're using a proper web service and not faking it in some way. The browser is not going to cache the webservice response.

Resources