fix: database lock by adding lock function when set schedule
Some checks failed
/ push (push) Has been cancelled

This commit is contained in:
Tigor Hutasuhut 2024-06-03 23:31:45 +07:00
parent c114469721
commit 0c784b4cc9

View file

@ -96,26 +96,28 @@ func (api *API) PubsubStartDownloadSubreddit(ctx context.Context, params PubsubS
return errs.Wrapw(err, "failed to verify subreddit existence", "params", params)
}
err = api.withTransaction(ctx, func(exec bob.Executor) error {
_, err := api.scheduleSet(ctx, exec, ScheduleSetParams{
Subreddit: subreddit.Name,
Status: ScheduleStatusEnqueued,
api.lockf(func() {
err = api.withTransaction(ctx, func(exec bob.Executor) error {
_, err := api.scheduleSet(ctx, exec, ScheduleSetParams{
Subreddit: subreddit.Name,
Status: ScheduleStatusEnqueued,
})
if err != nil {
return err
}
payload, err := json.Marshal(subreddit)
if err != nil {
return errs.Wrapw(err, "failed to marshal subreddit")
}
err = api.publisher.Publish(downloadTopic, message.NewMessage(watermill.NewUUID(), payload))
if err != nil {
return errs.Wrapw(err, "failed to enqueue reddit download", "params", params)
}
return nil
})
if err != nil {
return err
}
payload, err := json.Marshal(subreddit)
if err != nil {
return errs.Wrapw(err, "failed to marshal subreddit")
}
err = api.publisher.Publish(downloadTopic, message.NewMessage(watermill.NewUUID(), payload))
if err != nil {
return errs.Wrapw(err, "failed to enqueue reddit download", "params", params)
}
return nil
})
return nil
return err
}