how to create backgroud service in flutter - flutter

how to create a background service in FLUTTER
with posh notification
I create an app but I went to integer a service to check the database when the app is not run
thank tou

I would recommend using Google Cloud Scheduler, which allows you to create CRON jobs which can send a request to your API, on a regular basis. The first three jobs are free.
If you also need to implement the actual function checking your database, have a look at Google Cloud Functions. Those can be written in Javascript or Typescript and call make calls to external APIs as long as you are on Blaze Plan (which includes the monthly free quotas).
The advantages are:
you get free credit when you create your account
depending on your needs you might not need more than the free monthly quota for Google Functions calls (first 2 millions invocations are free every month)
it's very easy to create a scheduled function which will picked up and run by the Cloud Scheduler
it's highly scalable and reliable so you don't have to worry about managing your own servers

Related

Running periodic queries on google cloud sql instance

I have a google cloud postgre instance and I'd like to run periodic sql queries on it and use the monitoring system to alert the user with the results.
How can I accomplish just using the gcp platform? Without having to develop a separate app.
As far as I am aware of, There is no Built-in feature for recurring queries in Cloud SQL at the moment.
So you have to implement your own. You can Use Cloud Scheduler to trigger a Cloud function (via HTTP/S endpoint) that runs the query on Cloud SQL and then notify the user in the way that suits your needs (I would recommend using pub/sub).
and you might want to save the result in a GCS bucket and the user is to pull the result from there.
Also, you might want to check BigQuery. It has a built-in feature of Scheduling queries.

how to achieve push Notifications without using firebase Cloud functions?

my APP Is Really Depends on push Notifications, for examples iF the app has two actors, owner, and user, if the owner posts something, the user must be notified, based on their locations and Engagement in the app, which means the System first searches the nearest user and notify him, Notification is performed based on the location of the user, the user who is found in the nearest location is notified first, so What I want to ask you is, is it possible to achieve this without using firebase Cloud functions, Since firebase Cloud functions are NOT Free at this time. it asks me Billing account but the payment method is not available in my country
Apologies for my previous reply, I misunderstood the situation,
Also another solution besides one signal, you can use FCM on your own server, via FirebaseAdmin SDK. If you have a NodeJS server, a simple one, you can perform all firebase functions on it. In the end, it's not an absolute necessity to use cloud functions, it's just more convenient for a simple task or a few functions than spinning up your own server just for notifications. I would advise to go with this solution, and you will have access to cloud firestore via the admin SDK, you'll feel right at home.
Firebase cloud functions requires billing info, but you aren't charged. You have 2 MILLION free api calls per month. Then every extra 1 million calls cost less than half a dollar.
Do you know what 2 Million API invocations per month means? That's 32 THOUSAND API calls per day. If your app is generating that much traffic, trust me, you will not be worrying about these costs.
You can use OneSignal if you want, but it's more work for you, and it's outside the Firebase ecosystem.
Go with cloud functions, when you are reaching the limit of the free tier of 2Million monthly API requests, you can start looking for investors in your app.

Create new Cloud Tasks queue on demand

I'm looking into Cloud Tasks as the backbone for an app I am building. The way I envision my app is that for each individual customer, a new queue will be created. This will allow me to take advantage of the inbuilt rate limit features of Google Tasks, which operate on a per-queue basis. This will mean I can easily adjust rates on a per-customer basis.
Unfortunately all I can find in the documentation is the ability to create a queue manually, using the GCloud CLI
Does anyone know a way that I can create a queue programatically, in response to a new customer signing up? Bonus if it's doable through Cloud Functions.
Alternatively is there better products out there that will let me spin up lots of queues simultaneously?

The best practices for running CloudFunctions regularly based on the timestamp of each user

We are developing an app on Flutter on the client side and Firebase on the server side. I'm thinking of running Cloud Functions regularly using Cloud Scheduler based on each user's timestamp.
My idea is to run Cloud Functions using Cloud Scheduler every day at 12:00. Only users who have a timestamp older than 10 days perform a specific action. Is this a best practice?
Or is it possible to process Cloud Functions using the user's timestamp as a trigger?
For example, Cloud Functions is triggered when 10 days have passed since the user's timestamp.
Update
The scenario is as follows.
Cloud Firestore
/user/${userId}/funcStatus/status

Document(status) field is
timestamp:last update date(e.g. 2019/10/31)


I want to execute Cloud Function after 10 days, that is, when it becomes 11/10.

However, the timestamp varies depending on the user. e.g, userA:10/31, userB:10/20
The first option is possible with scheduled functions.
The second option is not possible with scheduled functions alone. You would have to use a Firestore onCreate trigger, then set up a callback with Cloud Tasks to get the function to execute at the right time.
Whichever one you choose is a matter of preference and whatever meets the needs of your app. There is no right or wrong way.

Pattern for Google Alerts-style service

I'm building an application that is constantly collecting data. I want to provide a customizable alerts system for users where they can specify parameters for the types of information they want to be notified about. On top of that, I'd like the user to be able to specify the frequency of alerts (as they come in, daily digest, weekly digest).
Are there any best practices or guides on this topic?
My instincts tell me queues and workers will be involved, but I'm not exactly sure how.
I'm using Parse.com as my database and will also likely index everything with Lucene-style search. So that opens up the possibility of a user specifying a query string to specify what alerts s/he wants.
If you're using Rails and Heroku and Parse, we've done something similar. We actually created a second Heroku app that did not have a web dyno -- it just has a worker dyno. That one can still access the same Parse.com account and runs all of its tasks in a rake task like they specify here:
https://devcenter.heroku.com/articles/scheduler#defining-tasks
We have a few classes that can handle the heavy lifting:
class EmailWorker
def self.send_daily_emails
# queries Parse for what it needs, loops through, sends emails
end
end
We also have the scheduler.rake in lib/tasks:
require 'parse-ruby-client'
task :send_daily_emails => :environment do
EmailWorker.send_daily_emails
end
Our scheduler panel in Heroku is something like this:
rake send_daily_emails
We set it to run every night. Note that the public-facing Heroku web app doesn't do this work but rather the "scheduler" version. You just need to make sure you push to both every time you update your code. This way it's free, but if you ever wanted to combine them it's simple as they're the same code base.
You can also test it by running heroku run rake send_daily_emails from your dev machine.