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

⭐ Serve mode with auto restart resouce on server #402

Open
websharik opened this issue Nov 28, 2022 · 0 comments
Open

⭐ Serve mode with auto restart resouce on server #402

websharik opened this issue Nov 28, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@websharik
Copy link
Contributor

websharik commented Nov 28, 2022

Replace IDE watcher to integrated watcher and use it as demon for this mode.
On change, compile with inject dev script as lualib and add to files .build with timestamp/hash.

Dev scripts

AutoRestart:

Looking .build file on the root resouce dir and on change restart resource.

import '.build' //Hello from https://github.com/mtasa-typescript/mtasa-lua-utils/issues/401

new (class AutoRestart {

    private fileName = '.build'
    private build = ''
    private interval = 5 //interval checks
    private wait = 5 //wait before restart
    private debug = false //show debug
    private timer: Timer

    constructor() {
        this.build = this.getResourceBuild()
        this.timer = setTimer(() => { this.checkBuild() }, this.interval * 1000, 0)
    }

    getResourceBuild () : string {
        if (fileExists(this.fileName)) {
            const file = fileOpen(this.fileName, true)
            const build = fileRead(file, fileGetSize(file))
            fileClose(file)
            return build
        } else return this.build
    }

    checkBuild() : void {
        if (this.build !== this.getResourceBuild()) {
            outputServerLog(`Build changed! Restart after ${this.wait} seconds...`)
            killTimer(this.timer)
            setTimer(() => {
                restartResource(getThisResource())
            }, this.wait * 1000, 1)
        } else if (this.debug) outputServerLog(`Build: ${this.build}/${this.getResourceBuild()}`)
    }
})
@websharik websharik added the enhancement New feature or request label Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant