mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-20 17:16:46 +00:00
fix(GODT-3124): Handling of sync child jobs
Improve the handling of sync child jobs to ensure it behaves correctly in all scenarios. The sync service now uses a isolated context to avoid all the pipeline stages shutting down before all the sync tasks have had the opportunity to run their course. The job waiter now immediately starts with a counter of 1 and waits until all the child and the parent job finish before considering the work to be finished. Finally, we also handle the case where a sync job can't be queued because the calling context has been cancelled.
This commit is contained in:
@ -119,7 +119,6 @@ func (j *Job) onJobFinished(ctx context.Context, lastMessageID string, count int
|
||||
// begin is expected to be called once the job enters the pipeline.
|
||||
func (j *Job) begin() {
|
||||
j.log.Info("Job started")
|
||||
j.jw.onTaskCreated()
|
||||
}
|
||||
|
||||
// end is expected to be called once the job has no further work left.
|
||||
@ -133,7 +132,6 @@ func (j *Job) waitAndClose(ctx context.Context) error {
|
||||
defer j.close()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
j.jw.onContextCancelled()
|
||||
<-j.jw.doneCh
|
||||
return ctx.Err()
|
||||
case e := <-j.jw.doneCh:
|
||||
@ -227,7 +225,6 @@ type JobWaiterMessage int
|
||||
const (
|
||||
JobWaiterMessageCreated JobWaiterMessage = iota
|
||||
JobWaiterMessageFinished
|
||||
JobWaiterMessageCtxErr
|
||||
)
|
||||
|
||||
type jobWaiterMessagePair struct {
|
||||
@ -248,7 +245,7 @@ type jobWaiter struct {
|
||||
func newJobWaiter(log *logrus.Entry, panicHandler async.PanicHandler) *jobWaiter {
|
||||
return &jobWaiter{
|
||||
ch: make(chan jobWaiterMessagePair),
|
||||
doneCh: make(chan error),
|
||||
doneCh: make(chan error, 2),
|
||||
log: log,
|
||||
panicHandler: panicHandler,
|
||||
}
|
||||
@ -273,15 +270,11 @@ func (j *jobWaiter) onTaskCreated() {
|
||||
j.sendMessage(JobWaiterMessageCreated, nil)
|
||||
}
|
||||
|
||||
func (j *jobWaiter) onContextCancelled() {
|
||||
j.sendMessage(JobWaiterMessageCtxErr, nil)
|
||||
}
|
||||
|
||||
func (j *jobWaiter) begin() {
|
||||
go func() {
|
||||
defer async.HandlePanic(j.panicHandler)
|
||||
|
||||
total := 0
|
||||
total := 1
|
||||
var err error
|
||||
|
||||
defer func() {
|
||||
@ -296,8 +289,6 @@ func (j *jobWaiter) begin() {
|
||||
}
|
||||
|
||||
switch m.m {
|
||||
case JobWaiterMessageCtxErr:
|
||||
// DO nothing
|
||||
case JobWaiterMessageCreated:
|
||||
total++
|
||||
case JobWaiterMessageFinished:
|
||||
|
||||
Reference in New Issue
Block a user