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

after_commit callback #191

Open
josh-m-sharpe opened this issue Jun 19, 2012 · 9 comments
Open

after_commit callback #191

josh-m-sharpe opened this issue Jun 19, 2012 · 9 comments

Comments

@josh-m-sharpe
Copy link

Is there any way to make the method defined by after_transition/do fire after the SQL commit has taken place?

I'm seeing race condition between state machine and resque. That is, if I drop an event in an after_transition, resque will pick up the job, and load the object before the initial transaction has been committed to the database - thus getting stale data.

If I dropped the event after the COMMIT has taken place, this would be a non-issue. Fixing this 'bug' on the resque side is hacky at best. I could lock, sleep, loop/repeat, meh, none of it looks good.

Thanks

@wijet
Copy link

wijet commented Jun 22, 2012

@crankharder Hi, we stumbled across the same problem and we came up with a simple after_commit queue. We have just extracted it into a gem https://github.com/shellycloud/after_commit_queue.

@johnreilly
Copy link

+1. We stumbled onto the same issue as @crankharder (though we're using sidekiq instead of resque).

@wijet, thanks for posting a workaround, I'll investigate it next. :)

@Gurpartap
Copy link

+1

Working good for me.

@flipkick
Copy link

+1

1 similar comment
@skyshard
Copy link

skyshard commented Jul 4, 2013

+1

@phlegx
Copy link

phlegx commented Oct 21, 2014

👍 Same problem using sidekiq and state_machine.

@anark
Copy link

anark commented Jan 3, 2015

+1

1 similar comment
@mgrachev
Copy link

👍

dzaporozhets added a commit to gitlabhq/gitlabhq that referenced this issue Sep 25, 2015
Fix bug where projects would appear to be stuck in the forked import state

A race condition existed between when Rails committed the `import_status` to
`started` and when the Sidekiq worker forked a project. If this fork were quick,
it's possible that the worker would attempt to move into the `finished` state
before the `started` state took effect.

As mentioned in https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting#cannot-find-modelname-with-id12345,
we can either delay the worker to ensure the DB has a chance to update, or use the nice `after_commit_queue` gem to schedule the task after the state machine commit. See:

* pluginaweek/state_machine#191 
* https://github.com/shellycloud/after_commit_queue


Closes #2736

See merge request !1434
dzaporozhets added a commit to gitlabhq/gitlabhq that referenced this issue Sep 29, 2015
Fix bug where projects would appear to be stuck in the forked import state

A race condition existed between when Rails committed the `import_status` to
`started` and when the Sidekiq worker forked a project. If this fork were quick,
it's possible that the worker would attempt to move into the `finished` state
before the `started` state took effect.

As mentioned in https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting#cannot-find-modelname-with-id12345,
we can either delay the worker to ensure the DB has a chance to update, or use the nice `after_commit_queue` gem to schedule the task after the state machine commit. See:

* pluginaweek/state_machine#191 
* https://github.com/shellycloud/after_commit_queue


Closes #2736

See merge request !1434
@sachin
Copy link

sachin commented Feb 18, 2016

Thanks it works perfectly

rymai pushed a commit to gitlabhq/gitlabhq that referenced this issue Oct 10, 2016
Fix ci pipeline processing with async jobs

## What does this MR do?

This MR fixes CI pipeline processing with asynchronous jobs called from `around_transition` provided by state machine.
For details see  pluginaweek/state_machine#191 and commit f68acba.

## Why was this MR needed?

Recently merged https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6650 introduced problem with asynchronous job being deployed when `around_transition` still held transaction, which caused race condition that prevented pipeline status to change in a proper way. 

## What are the relevant issue numbers?

Closes #23111

See merge request !6736
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

10 participants