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

Add Prosopite.pause and Prosopite.resume #32

Merged
merged 1 commit into from
Nov 13, 2021

Conversation

ghiculescu
Copy link
Contributor

I'm trying to migrate over from Bullet. We have a Delayed Job plugin at the moment, that disables Bullet while a background job is running and re-enables it when the job is complete. This way we can run Bullet in tests but have it only run on foreground code.

It looks this:

module Delayed
  module Plugins
    class BulletDisable < Plugin
      callbacks do |lifecycle|
        lifecycle.around(:invoke_job) do |job, *args, &block|
          @bullet_was_enabled = Bullet.enabled?
          Bullet.enabled = false
          block.call(job, *args)
          Bullet.enabled = @bullet_was_enabled
        end
      end
    end
  end
end

This PR adds Prosopite.pause and Prosopite.resume which allows you to do the same thing with Prosopite. So our plugin would become this:

module Delayed
  module Plugins
    class ProsopitePause < Plugin
      callbacks do |lifecycle|
        lifecycle.around(:invoke_job) do |job, *args, &block|
          Prosopite.pause
          block.call(job, *args)
          Prosopite.resume
        end
      end
    end
  end
end

I'm trying to migrate over from Bullet. We have a Delayed Job plugin at the moment, that disables Bullet while a background job is running and re-enables it when the job is complete. This way we can run Bullet in tests but have it only run on foreground code.

It looks this:

```ruby
module Delayed
  module Plugins
    class BulletDisable < Plugin
      callbacks do |lifecycle|
        lifecycle.around(:invoke_job) do |job, *args, &block|
          @bullet_was_enabled = Bullet.enabled?
          Bullet.enabled = false
          block.call(job, *args)
          Bullet.enabled = @bullet_was_enabled
        end
      end
    end
  end
end
```

This PR adds `Prosopite.pause` and `Prosopite.resume` which allows you to do the same thing with Prosopite. So our plugin would become this:

```ruby
module Delayed
  module Plugins
    class ProsopitePause < Plugin
      callbacks do |lifecycle|
        lifecycle.around(:invoke_job) do |job, *args, &block|
          Prosopite.pause
          block.call(job, *args)
          Prosopite.resume
        end
      end
    end
  end
end
```
@charkost charkost merged commit cba0026 into charkost:main Nov 13, 2021
@charkost
Copy link
Owner

Awesome @ghiculescu, thank you!

@ghiculescu ghiculescu deleted the pause-and-resume branch November 13, 2021 14:19
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

Successfully merging this pull request may close these issues.

None yet

2 participants