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

only run one instance 'cron.run()' #46

Closed
winxxp opened this issue Feb 24, 2016 · 6 comments
Closed

only run one instance 'cron.run()' #46

winxxp opened this issue Feb 24, 2016 · 6 comments

Comments

@winxxp
Copy link

winxxp commented Feb 24, 2016

If call twice

func (c *Cron) Start() {
    c.running = true
    go c.run()
}
@elgs
Copy link

elgs commented Feb 24, 2016

So is this a question or a statement?

@winxxp
Copy link
Author

winxxp commented Feb 25, 2016

I mean Start() method shoud be a singleton method, to protected call Start() many times, or appliction must be protected self.

@elgs
Copy link

elgs commented Feb 25, 2016

@winxxp thanks. That makes sense. Probably the Start should be like this:

func (c *Cron) Start() {
    if c.running {
        return
    }
    c.running = true
    go c.run()
}

@winxxp
Copy link
Author

winxxp commented Feb 25, 2016

thread-safe better.

@dmitshur
Copy link

Is there a good reason your application can't call Start once?

Or are you saying, in case a poorly behaved application calls Start more than once, then cron should handle that situation better?

@winxxp
Copy link
Author

winxxp commented Feb 26, 2016

I used zookeeper to elect master, when network broken or other slave online, all node recvived new nodes to elect new leader, if leader call start, or stop, sometime the elected reslt is the leader node also leader node, so it call twice or more.

Now I protected it out Start/Stop self.

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

No branches or pull requests

3 participants