Given the starting time/date and duration, how can I make a server side calculation that determines if an object is "finished", "in progress", or "upcoming"
--Show
--duration: "144"
--startDate: "2015-11-10"
--startTime: "14:00"
--status: "?"
Client-side javascript to determine if the show has started yet:
// if negative, then show hasn't started yet
var time = (-(startdate.getTime() - currentdate.getTime()) / 1000 / 60);
Client-side javascript to determine if the show has finished running yet:
// if negative, then show has finished
var timeLeft = channelDuration - timerStartTime;
There is no way to run your own server-side code on Firebase. See:
Common Firebase application architectures
Firebase Hosting with own server node.js
How would I run server-side code in Firebase?
How to write custom code (logic) when using firebase
But you can store a server-side timestamp, which seems what you're trying to do:
ref.child('Show/startTimestamp').set(Firebase.ServerValue.TIMESTAMP);
You can then get the shows that haven't started yet with:
var shows = ref.child('Shows');
ref.orderByChild('startTimeStamp').startAt(Date.now()).on(...
For someone passing by, I think now Firebase allow you to do this by Cloud Function. For this case, you can create the function that determine the status of the status by other parameter when the data is added to you database.
Please checkout
https://firebase.google.com/docs/functions/
Related
In the chat history (summary) page of my app I'm using the function getUnreadCount() on MesiboProfile to get the number of messages currently unread so that I can show an indicator near the message.
The problem is that count is only correct the first time I read the summary from the read session. If it arrives a new message when I already read the summary, that count is not updated.
I saw that the counter gets fixed if I read the summary again but is this the recommended way to update that counter?
I'm using the iOS SDK v1.9.55
In 1.x, the unread count can be updated manually. Set the unread count to zero once you read it or increment it every time you receive a new message. This avoids database access. Here is the 1.x code which does the same.
Update: you can also use getUnreadMessageCount() in the user or group readsession (not the summary session) to get it from the database.
https://github.com/mesibo/ui-modules-ios/blob/master/Messaging/Messaging/UserListViewController.m#L474
In 2.x, we have moved this to API with additional logic.
I have created a watch Channel on my calender and I am successfully receiving all updates from Google PUSH Notifcation.
But I am not able to use that response to get craeted/updated events.
I read few docs and SO questions that I need to use X-Goog-Resource-ID from the response and hit events list API.
But value of this X-Goog-Resource-ID is neither a calender id and neither it is a event id so how can I use this in events list API ?
I am using Python and Service Account for the integration.
Documentaion :
https://googleapis.github.io/google-api-python-client/docs/dyn/calendar_v3.events.html#list
https://developers.google.com/calendar/api/guides/push#making-watch-requests
Response from PUSH :
"X-Goog-Channel-Expiration": "",
"X-Goog-Channel-ID": "",
"X-Goog-Channel-Token": "",
"X-Goog-Message-Number": "",
"X-Goog-Resource-ID": <resource id>,
"X-Goog-Resource-State": "exists",
"X-Goog-Resource-URI": <calender UI>
Google Functions I tried using :
service = build('calendar', 'v3', credentials=credentials)
service.calendars().get(calendarId=X-Goog-Resource-ID).execute()
service.events().list(calendarId=calenderId', eventId=X-Goog-Resource-ID).execute()
Is their any ref Python Example of using digesting Calender PUSH Notification or which API/Function I need to call with what oaarms to get the created/updated events ?
The X-Goog-Resource-ID header holds a value that identifies that particular resource across the APIs. The whole push notifications basically informs you that something has changed on that calendar.
Now if you want to know exactly what changed, I strongly advise you to perform a synchronisation. One way to do this is to perform a full synchronisation and store the nextSyncToken. Then, when you receive a push notification telling you about a change in the calendar, you only have to use the syncToken to know what has changed since your last synchronisation. You can see a working full example on the linked docs.
UPDATE
If you are watching multiple calendars through push notifications, you will need a system in place to track which calendar is being modified at a time. The X-Goog-Resource-ID header maps with the Calendar ID, and it can be used along syncToken to run a events.list() request to receive the updated events.
Can anyone give me any advice on how to create an LP pool on the Solana devnet?
I planned this job for testing swaps between specific two tokens on the devnet using the Raydium protocol.
So, I need to create a swap pool on the devnet first.
To achieve this, I did it like below.
First of all, to list on the serum market, I cloned the Raydium-Dex repository on my mac and changed the Serum dex's program id from the mainnet to the devnet, and I success registered on the devnet serum. (Custom token with SOL pairs)
As a result, I got a serum market program id.
After that, I cloned the Raydium-frontend repository to create a liquidity pool. And modified wellknownToken.config.ts so that my custom tokens could be possible to create a new pool.
Finally, I could access the create pool UI from the localhost web UI.
I clicked Initialize Liquidity Pool button on the UI and got a Toast message Create a new pool Transaction Sent apparently.
However, It is not worked well. Because I can not find the transaction hash on the Solscan website.
I tracked the button's click event codes and I figured out one thing.
One of the result value of Liquidity.makeCreatePoolTransaction function has a null value, especially, feePayer.
const { transaction: sdkTransaction1, signers: sdkSigners1 } = Liquidity.makeCreatePoolTransaction({
poolKeys: sdkAssociatedPoolKeys,
userKeys: { payer: owner }
})
const testTx = await loadTransaction({ transaction: sdkTransaction1, signers: sdkSigners1 })
console.log('feepayer', testTx.feePayer?.toBase58()) // null
I felt this is not the preferred (good) way to create a swap pool on the Solana devnet, but I can not find a better way to achieve this task.
What am I missing? or What am I should read or learn?
please give me some advice on how to do it to make it works.
Thanks.
It looks like the transaction created with Liquidity.makeCreatePoolTransaction hasn't been sent to the network, so it doesn't exist anywhere. Be sure to send and confirm the transaction before trying to load it. You can use something like:
const { transaction: sdkTransaction1, signers: sdkSigners1 } = Liquidity.makeCreatePoolTransaction({
poolKeys: sdkAssociatedPoolKeys,
userKeys: { payer: owner }
});
await sendAndConfirmTransaction(connection, transaction, [wallet]);
Note that this requires a connection to send and a wallet to sign. More info at https://github.com/solana-labs/solana/blob/9ac2245970de90af30bff9d1f7f35cd2d8f2bf6d/web3.js/src/util/send-and-confirm-transaction.ts#L18
You might run into other issues though, because the Raydium program isn't deployed to devnet: https://explorer.solana.com/address/675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8?cluster=devnet
I want to send the creation time of a Firestore document through the client and verify the time with Firestore Rules to avoid Cloud Functions calls (pricing).
Scenario
I am testing requests from clients against Firestore rules like this:
allow create: if request.resource.data.TIMEFIELD == request.time;
The request contains a TIMEFIELD that has a timestamp, just like request.time.
Problem
Apparently the request time and the time I am setting as a field right before sending the request are not equivalent, which makes this comparison impossible.
The following is the defition of request.time from the documentation.
When the request was received by the service.
I wonder if there is a way to set a field in a document equal to request.time.
I am unable to use server side timestamps because of an issue with Flutter.
Because of that I need to know how I could possibly validate client side timestamps like time.now with Firestore Rules.
You can use the Timestamp to add constraints to the time field (docs).
Here is an example of how to ensure that the change was within a certain amount of seconds:
function withinSeconds(secs) {
return request.resource.data.TIMEFIELD.seconds() - request.time.seconds() <= secs
&& request.resource.data.TIMEFIELD.seconds() - request.time.seconds() >= -secs
}
Edit
The above is for setting the value within a threshold of the request.time.
You can also just use the REST API in the mean time. Just make a write request that includes an update and a transform. The transform is where you would set the server timestamp. Here is a tool to help understand how to build the requests.
This has been implemented into the Flutter plugin for Cloud Firestore:
FieldValue.serverTimestamp()
Using this as a field's value will assign a timestamp equal to request.time to the field, server-side.
You can find out more about it in the API reference for cloud_firestore.
you'd first have to remember the creation (or last updated) timestamp:
firestore().collection("items").add({
....
created: firebase.firestore.FieldValue.serverTimestamp()
});
in order to let the client know of the timestamp, which you are trying to compare later on.
We have a notification which will post data to an application using the application end point.
notification ABC{
post = savedetailsurl
body = {{.|json}}
useBody = true
}
So the end point will save all the details in mysql DB.
Now in our template we call another end point to get the details which we saved using the webhook in notification.
template ABC {
use the " getDetailsUrl" and use the details in forming the email
}
Now the problem is race condition. Sometimes the details are not saved yet in the backend (mysql), and getDetailsUrl is called. So we get the empty result.
Is there are way to solve the race condition.
Bosun's notification system is designed to be very basic. If you want something more advanced you will need to use a separate system to generate the notification details and/or handle the alert workflow. Some people have used pagerduty or other monitoring systems like Shinken to do more advanced notifications or alert management.
Your best bet is to skip the built in notifications and do everything in a external system. You can still use the http://bosun.org/api to integrate with the various alert states (crit/warn/ack/close/etc) or you can change your alerts to use log = true to bypass all the built in states and create your own workflow.