Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add api endpoint to generate and serve cached file #1

Merged
merged 44 commits into from
May 5, 2023
Merged

Conversation

wa0x6e
Copy link
Contributor

@wa0x6e wa0x6e commented Apr 19, 2023

Changes

This PR adds the endpoint to serve/generate a cached file.

In case the cached file does not exist yet, a generation task will be triggered, and a PENDING_GENERATION response will be returned instead.

There's also a dedicated endpoint to trigger the cache file generation

A queue system is used for cache file generation:

  • to ensure uniqueness
  • to avoid awaiting the cache generation (which can take some time), when sending the POST request

Todo

@wa0x6e wa0x6e requested a review from bonustrack April 19, 2023 18:41
@wa0x6e wa0x6e marked this pull request as draft April 20, 2023 09:16
@wa0x6e wa0x6e marked this pull request as ready for review April 22, 2023 14:52
@wa0x6e wa0x6e marked this pull request as draft April 22, 2023 16:10
@wa0x6e wa0x6e marked this pull request as ready for review April 22, 2023 19:15
@samuveth samuveth requested a review from Todmy May 3, 2023 09:56
@wa0x6e
Copy link
Contributor Author

wa0x6e commented May 3, 2023

@ChaituVR ?

Copy link
Member

@ChaituVR ChaituVR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get this error, I did yarn install and yarn dev then i see this error

snapshot-sidekick/node_modules/ts-invariant/lib/invariant.js:11
        var _this = _super.call(this, typeof message === "number"
                           ^
Invariant Violation: 
"fetch" has not been found globally and no fetcher has been configured. To fix this, install a fetch package (like https://www.npmjs.com/package/cross-fetch), instantiate the fetcher, and pass it into your HttpLink constructor. For example:

import fetch from 'cross-fetch';
import { ApolloClient, HttpLink } from '@apollo/client';
const client = new ApolloClient({
  link: new HttpLink({ uri: '/graphql', fetch })
});

I think we should add cross-fetch as a dependency

@wa0x6e
Copy link
Contributor Author

wa0x6e commented May 3, 2023

Native node fetch is only available from node 18

@ChaituVR
Copy link
Member

ChaituVR commented May 3, 2023

Native node fetch is only available from node 18

Hmm, we should restrict this to node 18 only with node engines in package.json, or add cross-fetch if we want to support other nodejs version

@wa0x6e
Copy link
Contributor Author

wa0x6e commented May 3, 2023

Added, make sense to always enforce node version, as the CI is only testing on node 18

@ChaituVR
Copy link
Member

ChaituVR commented May 3, 2023

Updated Readme (not sure how to suggest so many changes so added a commit, feel free to modify if required)

@wa0x6e
Copy link
Contributor Author

wa0x6e commented May 3, 2023

Readme update seems good

@wa0x6e
Copy link
Contributor Author

wa0x6e commented May 3, 2023

If you have your own aws api keys for S3, please also do test that. The keys provided for the production were returning an error, but my personal one do work.

Prod will use AWS

}

export function voteReportWithStorage(id: string) {
return new VotesReport(id, new StorageEngine('votes'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add this votes at the config level, or maybe a global variable in this file? In case we want to change the folder name in future

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean a config file like config.ts not needed in .env

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did go the .env route. Allow dev to each have their own preferences, without having unstaged changes in the repo. Also can customize the storage engine on prod or staging server, without having to edit the source code. wdyt?


get = async (key: string) => {
try {
const command = new GetObjectCommand({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can use putObject and getObject like in other repos?
https://github.com/snapshot-labs/subgrapher/blob/main/src/aws.ts#L22

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other repos are using the old v2 sdk. In the long term, I think we should just move over to the new v3 syntax everywhere.

We're already using the v3 modularized version of their SDK (@aws-sdk/client-s3), why not also follow the recommended syntax that's shipped with it.

Their new API provides new features, like the transformToString() method on the response's body, saving us from using a custom streamToString function (https://github.com/snapshot-labs/subgrapher/blob/32d43b22603662e7410a9e0be8d62faeca5f233c/src/aws.ts#L11)

Copy link
Contributor

@samuveth samuveth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

I think we can fix any other issues post merge @ChaituVR

@bonustrack
Copy link
Member

@samuveth We should avoid untested review and merge should be done by the author of the PR. This PR require new conf vars for example I dont think it should have been merged that fast.

@ChaituVR
Copy link
Member

ChaituVR commented May 5, 2023

@samuveth It is not a very urgent issue on Snapshot, right?

It is not just about testing/issues 😄 we should also check the code, right? else we could be in trouble in the future/can take more time to understand everything. ideally, everyone in the team should be able to work on changes on this very easily (not saying this PR code is bad 😄 but generally speaking)
@bonustrack will not merge any PR unless everything is perfect 😅 including all variable names. maybe we should follow him?

Of course, I agree I was bit busy with other things and delayed this but I believe we should give more time to reviews.

@aurelianoB please suggest some flow and schedule for reviewers :) maybe teams should leave a few weekdays to just test/review/rework? right now it is hard to plan/schedule reviews 🤔 because we never know what the other team is working on and when they request a review, also it is hard to know their priorities

@samuveth
Copy link
Contributor

samuveth commented May 6, 2023

Sorry guys, shouldn't have merged this myself you are right.

@ChaituVR Regarding the review schedule, I make it a point to check for requested reviews twice daily - once in the morning and once in the evening. I aim to complete these reviews promptly. In my view, it's important to prioritize reviews at least once a day, as this approach can effectively streamline project progress and ensure that team members receive timely feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants