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

fix sync issue #2233

Merged
merged 3 commits into from
Aug 13, 2019
Merged

fix sync issue #2233

merged 3 commits into from
Aug 13, 2019

Conversation

allardy
Copy link
Member

@allardy allardy commented Aug 13, 2019

When actions are edited using the code-editor and a database, we need to sync them back to the file system so they can be required() by actions and hooks. VM2 can't load them from the ghost.

This PR fixes an issue where there was way too many invalidate triggered for nothing. It is triggered once when a file is inserted, then it is propagated to other nodes via redis

Copy link
Member

@EFF EFF left a comment

Choose a reason for hiding this comment

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

code seems fine but i'm a bit worried with ghost sync, let's talk about this quickly

const botId = parts[parts.indexOf('actions') - 1]

// Debouncing invalidate since we get a lot of events when it happens
private _invalidateRequire() {
Copy link
Member

Choose a reason for hiding this comment

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

not that I care about this change to be made but what about :

private _invalidateRequire = _.debounce(() => {
  // code goes here
})
// and get rid of the constructor initialization for the func

@@ -17,7 +17,7 @@ import { VmRunner } from '../action/vm'
import { Incident } from '../alerting-service'

const debug = DEBUG('hooks')
const SYNC_DEBOUNCE_DELAY = ms('2s')
const DEBOUNCE_DELAY = ms('2s')
Copy link
Member

Choose a reason for hiding this comment

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

I know its not part of this PR but it seems to me that the code here and in action service is pretty much duplicated

@@ -215,6 +238,10 @@ export class ScopedGhostService {
await this.primaryDriver.upsertFile(fileName, content, recordRevision)
this.events.emit('changed', fileName)
await this._invalidateFile(fileName)

if (syncDbToDisk) {
await this.cache.sync(JSON.stringify({ rootFolder, botId: this.botId }))
Copy link
Member

Choose a reason for hiding this comment

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

why not leave the responsibility of serializing the obj do the sync method ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Trying to keep the logic in redis cache minimal

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.

2 participants