Do webhook events contain a timestamp? How can I know if an event has been emitted before another one? #61851
-
Select Topic AreaQuestion BodyHi 🙂 I'm implementing a GitHub App. Because this is event-based, to update my DB I need to be sure of the ordering of the events before updating the state of an installation in my DB. If I receive or process the events in the incorrect order, the result could be that the state of the installation in my DB would be incoherent with the state of the installation in GitHub. Let's take an example. I can't find this information/timestamp in the GitHub webhooks doc nor in the payloads I receive from the webhook. Do the events emitted (or the request headers) contain this information? Thanks for your help, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
|
If anyone reads this one day, the "solution" I've found above isn't really a solution because in some events there's no More details, see: https://twitter.com/guizmaii/status/1691048850318823424?s=20 |
Beta Was this translation helpful? Give feedback.
-
|
@guizmaii I understand that this is a long way down the road and you may not even mind, but this is the post that came up when I went looking for the timestamp of an event with GitHub Webhook and thought it's worth tossing my findings here. When looking at all the available headers, I spotted that Not sure how common knowledge this is, but a UUIDV1 contains a timestamp and lucky for us So I was able to derive a timestamp from your event and it seems like it matches up! const uuidTime = function (uuid) {
// Split the UUID string into an array
const uuidArr = uuid.split('-');
const timeStr = uuidArr[2].substring(1) + uuidArr[1] + uuidArr[0];
// Convert the time string to an integer, adjusting for the UUID epoch
const uuidTime = parseInt(timeStr, 16) - 122192928000000000;
const uuidMillis = Math.floor(uuidTime / 10000);
return new Date(uuidMillis);
};
// Convert X-GitHub-Delivery header to Event Timestamp
const date = uuidTime("0d2dd4d0-2c4f-11ee-8d9f-85919bcb71e8");
console.log(date); |
Beta Was this translation helpful? Give feedback.

If anyone reads this one day, the "solution" I've found above isn't really a solution because in some events there's no
created_atnorupdated_atfield. Basically, no date at all in the event, which means that we cannot always derive a timestamp for the event from its content, which means that some events are not timestamped at all.More details, see: https://twitter.com/guizmaii/status/1691048850318823424?s=20