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

Lock function, still run multiple times on multiple server instances #160

Open
g-graziano opened this issue Jul 23, 2020 · 3 comments
Open

Comments

@g-graziano
Copy link

g-graziano commented Jul 23, 2020

i used lock implementation on redis, but it still run cron multiple times on multiple instances, i have 4 instances and it still run 4 times

locker := p.schedulerLockerRepo
gocron.SetLocker(locker)
go p.paymentDailyReminderWorker()

func paymentDailyReminderWorker() {
	reminderScheduler := gocron.NewScheduler()
	if err := reminderScheduler.Every(1).Day().At(c.config.DailyReminderClock).Lock().Do(c.processPaymentReminder); err == nil {
		c.logger.Info().Str("reminder_at", c.config.DailyReminderClock).Msg("payment daily reminder worker started")
		<-reminderScheduler.Start()
	}
}
@arjunmahishi
Copy link
Contributor

Hey @g-graziano, This project is now being maintained in this repo. You might want to check that out and see if this issue is still occurring. If it is, we can track this issue there.

@rtywei
Copy link

rtywei commented Jun 3, 2021

This problem does exist, and the result of lock acquisition is not judged in the implementation.

func (j *Job) run() ([]reflect.Value, error) {
	if j.lock {
		if locker == nil {
			return nil, fmt.Errorf("trying to lock %s with nil locker", j.jobFunc)
		}
		key := getFunctionKey(j.jobFunc)
                 **// This result is not judged`**
		locker.Lock(key)
                **// This result is not judged`**
		defer locker.Unlock(key)
	}
	result, err := callJobFuncWithParams(j.funcs[j.jobFunc], j.fparams[j.jobFunc])
	if err != nil {
		return nil, err
	}
	return result, nil
}

@JohnRoesler
Copy link
Contributor

hi @rtywei as @arjunmahishi mentioned - this repo is no longer maintained. We are maintaining it over at https://github.com/go-co-op/gocron but we have since removed the locker mechanism as it was not working and we have yet to come up with a good implementation.

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

4 participants