Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
In my application I do a ranking of the points of a user. However, I do the calculation of my ranking just every 24 hours. My problem is that I do not know where I should put the code of the calculation without disturbing the user.
Is it not possible to have a code in the "background" who will be called every 24h? Because at the moment, the code for the calculation is called when the first user uses my app after 24h, but then the user has to wait some minutes until the calculation is over. My data of every user is saved with Firebase.
Thanks in advance!
Edit April 22, 2019:
Recently, Google Cloud released Cloud Scheduler, which allows you to schedule HTTP requests or Cloud Pub/Sub messages to functions that you deploy.
This new service works also very well with Firebase and for that I recommend you read an excellent article writen by Doug Stevenson on the Firebase blog named Scheduling Cloud Functions for Firebase (cron).
Is it not possible to have a code in the "background" who will be called every 24h?
Yes, it is possible. In this case, you should write a function in Cloud Functions for Firebase and call it whenever you needed. If you want to be triggred every 24 hours, use the follwing service:
https://cron-job.org/en/
This means that you can do that particular calculation even if the user has the app closed. For a code example, please see Frank van Puffelen's answer from the following post:
Cloud Functions for Firebase trigger on time?
For your case I'd recommend using default Android tools for scheduling jobs. You can try using a new WorkManager or just a JobScheduler. Also you can try digging into this article to get more information.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
It seems like there are two choices with firebase for sending and receiving "moves" between players in a 'serverless' two player game. I could either use FCM and firebase cloud functions to send and send receive messages between the players,
i.e. player 1 calls a cloud function to communicate a "move" and the function calls FCM to send a message to the opponent a "move" was initiated by the other player.
or I could have both players observe the "game state" document in firestore, so that each player calls a cloud function to update the game state, and the other player is notified about the opponents move when the observer of the "game state" document registers a change in the document.
Neither of these approaches seems ideal fo the purpose, using the game state document seems a little easier perhaps could be because I understand firestore better than FCM.
just wondering what the "best practice" is for handling this kind of bilateral signalling between two users. (I guess the same basic question would arise in trying to build a "chat function" between two users on an web app. (the app itself is built in Angular) and just uses local code, a few cloud functions and a firestore, but no dedicated server.
If you want to use Firebase for this I would recommend to use the realtimedatabase. The FCM can have some lag when delivering and it depends on multiple stuff you can't control like battery status, etc. (the OS decidec more when to get new messages). By using the realtime database you are in control when it happens. I would not use Firestore because you are charged there for reads and writes and you will probably have a lot of them.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am making a web game. When certain time is reached, a new round should begin. Therefore, a firestore document should be changed at the time. I implemented this by calling a cloud function locally, counting timer on the client with the local time. However if the client closes the connection, the cloud function cannot be launched. How could I solve this problem?
Thank you.
I found out that google cloud scheduler functions has evolved to cloud tasks. I think this would perfectly match my circumstances. Having a look at the documentation.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am working on a flutter project with payment integration. I am very good at front end side but when it comes to back-end it hurts. Anyways I want to add this functionality in my app.
The user will pay price for the consultant. Once the transaction is done I want to give the user a option to chat with the support team of the app but for only 2 days not more than 2 days after the payment. I am using purely using firebase for CRUD functions but I am stuck on this. I have done this in php with sessions but I can't figure out how can I do it using firebase.
Any detailed help/guidance will be very helpful.
Thanks.
save user profile inside firestore in a users collection
add a boolean field called subscribed which is an indicator for the user payment, and subscriptionDate
when the user subscribes, record the dattime
every time the user opens your app, first check if he's subscribed or not, then compare the current date with the subscriptionDate
if the user passed the previous step, open the chat page
you can find many tutorials on google that talks about building chat app using firebase in details
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
So I'm building a web shop using Firestore and Firebase for the first time, I'm also new to NoSQL. I have the following architectural problem: When a customer places an order the client sends the products ordered to Firestore directly which stores the order in a collection raw_orders. My idea then was to have a Cloud Function trigger on the document create which processes it and builds an invoice and such. However I read that this function invocation may be delayed for 10 seconds, I would like to have a synchronous solution instead.
Instead I had the idea to create a HTTP Cloud Function where the customer can POST the order to, the HTTP function then processes the order and pushes it to Firestore, the function then returns the orderID or something to the customer. This approach feels much more safe since the user won't have to talk to the database directly. Also it solves the issues that the a function triggered by a Firestore create might be delayed.
However I'm new to Firebase and I'm not sure if this is architecturally the preferred way. The method I propose seems to be more in line with regular old REST APIs.
What do you think?
Thanks!
It sounds like you definitely have some server-side code and database operations that you can't trust the clients to do. (Keep in mind that firestore security rules are your only protection -- anyone can run whatever code they want within those rules, not just the code you provide).
Cloud functions give you exactly this -- and since you both want the operation to be synchronous (from the view of your client) and presumably have some way for the client to react to errors in the process, a cloud function would make a lot of sense for you to use.
Using cloud functions in this way is very common in Firebase apps, even if it isn't pure REST.
Moreover, if you are using Firebase more generally in your client, it might be more natural to use a callable cloud function rather than an http function, as this will handle the marshaling of the parameters in a much more native way than a raw HTTP request might. However, it isn't clear in your case since it sounds like you're using the REST API today.
Keep in mind that there are additional costs (or specific quotas, depending on your pricing plan) for running cloud functions. The pricing is based on invocations, as well as CPU and RAM usage of your functions.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have this amazing flutter app and I managed to set up a payment system with Stripe. My app is a marketplace so I have many vendors and I am able to collect money from the users and transfer the money to vendors. I have create a test vendor and it all works fine in testing mode. Now I would like to let prospective vendors to create a Stripe standard account and connect with my platform. Here are the instruction I would need to follow: link to stripe
I read the instructions but I am not able to understand or implement it. I would like to know if I can implement the steps within my Flutter app or not. I am not familiar with servers but I have managed to use firebase to create charges. My first problem is the redirect URI (what is this?). The second problem is how to handle the response from stripe (step 3) and lastly get the vendor data with a POST request... Is there anything simple to use in flutter? I have seen this and this but I am not sure they can be used...
Can you please clarify what should I do here. Many many thanks in advance
Here is what I did
in firebase: I created an http function, ie exports.createStripeAccount = functions.https.onRequest((req, res)
in stripe: set that function as redirect uri
in flutter: launch(url_to_connect_the_account)
in firebase inside the httpfunction:
return stripe.oauth.token({
grant_type: 'authorization_code',
code: req.query.code,
})
and that's all folks!