DEV Community

Amazing
Amazing

Posted on

Release 0.4: Unfinish work

Implement ttl to check the expired invalid key

The implementation is quite simple than I thought. First I come to the src/api/posts/src/storage.js and adding a simple change, so when we set an invalid

setInvalidFeed: (id, reason) => {
    const key = createInvalidFeedKey(id);
    const expireAfter = 60 * 60 * 24 * 7; // Expire after 7 days
    return redis.set(key, reason, 'EX', expireAfter);
  },
Enter fullscreen mode Exit fullscreen mode

But the testing would be a bit tricky, as first I just restart all the images and cd into src\backend and run npm start. After talking with Emily I come to my ubuntu and type
sudo docker exec -it redis sh and using redis-cli I would be able to use commands to interact with the redis data. I would search for the invalid key using keys *invalid and I pick out a random key ttl key but the result retunred -1 which prefer to the doc

The command returns -1 if the key exists but has no associated expire

So clearly the change did not work or my prediction would be that I have to wait for the new invalid feed to come up which my change would be apply to but after a long time waiting I regconize that I might be able to delete all the data. I came into my project and rm -f redis-data and after that my project stop working and I have to ask the maitaince of the project to kindly send me the redis-data folder again.

After that, I found out that we would be able to use flushall in the redis-cli to clear all the invalid key and after run the project again. My change clearly did not work at all.

After talking with Emily she also suggest me to come to src/backend/utils/storage.js and change the same line of codes. It seem surpising to me when we have two indentical code at two different places of the project but the change did the job

Image description

After talking with some of the folks in the Slack channel which have more experience. They have kindly explain

that's because initially we had only one back-end (the one inside the backend folder) doing everything, and as we started developing microservices, we had to move the code to the microservices using that code. The easiest way was to copy the whole chunk of code from the old backend to the microservice you're working on, but sometimes you might copy parts that you don't need, like setInvalidFeed in this case

This has not make a lot of sense to me yet because of my knowledge about the project but I will note it here for feature preference

You can check out my PR

Another trick that I learn when using Git

When talking and working with Duke, we try to co-operate and using Gitpod for our work so I upload a dummy version of what I got on branch issue-2569 butn since I did not be able to pull off the second requirement of the issue and I need to submit my PR. I come into the project and use git reset --soft and discard the change from the MOCK_REDIS = and changes in the proccesor.js then push -f back into the branch.

I can say I get a bit handy with git and understand the flow of it now after 14 weeks !

Top comments (0)