Looking for help regarding odd Glitch + Slack + JSON db behavior

Hello! I have a Slack app hooked up to Glitch. Glitch handles all the app’s db inputs and requests for data initiated from Slack via JSON db. The inputs and outputs are JSON objects. For example, they have titles, dates, and descriptions.

Recently, my team and I noticed weird behavior. When a user submits info, it’s not immediately available for retrieval. Checking the JSON db file on Glitch also doesn’t show the new data. But on the Slack side via the modals that are capable of requesting data, we can see parts of the JSON object that were sent over to Glitch e.g. the title. But interacting with it isn’t possible.

On Glitch however, we realized that entering “refresh” in the terminal synced up the editor with the terminal. After doing this, the JSON db file populates and on the Slack side, the JSON object is accessible (this is expected behavior). If we don’t do this, the update happens eventually on its own. It can happen anywhere between 30 minutes - 24 hours.

Since this is an app that should work in real-time, manually refreshing is unreasonable. Implementing a patch that submits a “refresh” to the terminal on some interval also doesn’t feel right.

For context, this project is boosted on Glitch. Has anyone encountered something similar?

I found a couple resources on here that helped to illuminate what is going on:

All relate to what I explained. So now, I am able to say this is more of a Glitch issue vs. a Slack or JSON db one.

So far, I’ve tried leveraging child_process mentioned in the last but the refresh takes anywhere from 30-60 seconds. I know that I can’t refresh a specific file (based on the second link’s info) but is refresh an all or nothing command? Can I limit it to a particular scope/directory?

Thanks in advance for any help anyone can offer.

Hi eb2021, welcome!

My understanding of the refresh thing is that while the updated file isn’t shown in the Glitch editor, it’s content has in fact been updated, and any calls into that file from - for example - your API, should get the latest file content.

Do I understand correctly from your message, that when you call into your Glitch project from Slack, it is still returning outdated JSON data?

Hello SteGriff! Thanks for the reply!

Yes, you’re understanding my post correctly. When we call into the Glitch project via Slack, it is almost as if the JSON data doesn’t exist because the data we’re requesting is inaccessible. But we know this isn’t true because we can see components of the object itself via Slack.

For additional context, we’re submitting JSON data with a title, date, and description. We request this info back in the event that the user wants to change details. We can see the title in the drop-down menus on Slack, but we’re unable to immediately access its contents without a refresh. Sometimes the data syncs up within 30 minutes; sometimes it takes up to 24 hours.

But it isn’t until a refresh that the expected behavior on Slack happens. On Glitch, the JSON file itself doesn’t have the information written when accessed via the editor (which makes sense given the editor-terminal sync issue). But for reference, when we refresh, the line count of this file jumps and immediately reflects all the data that was submitted via Slack.

Hey again,

Ok, this behaviour is unfortunately beyond me! I haven’t seen that but I believe you, it must happen in certain situations. Maybe at some point I’ll put together a minimal project to reproduce it…

In the meantime, you can hit up support@glitch.com or there may be others on the forum who can advise, @wh0 knows a lot of edge cases, and @jenn is staff here.

Good luck!

2 Likes

Hi eb. I wonder if you’re using require to load the JSON file. I’ve seen in some other threads that it caches the file throughout the process’s lifetime, meaning it won’t see changes made after the first call to require. The lower level fs API would let you read files as needed, but you’ll probably need some coordination to make sure you’re not reading while another write is going on. This seems consistent with what you’re experiencing. Running refresh also restarts your app too, so it’ll be a new process that rereads the JSON file.

If you’re routinely looking at the file in the Glitch editor, you could try running enable-ssm to make Glitch update the editor when your app makes changes to files. I think it’s still experimental though. And it won’t restart your app, so you’ll still have to do something to reread the JSON file from that side.

@SteGriff thanks for finding an interesting thread!

1 Like