Giter Site home page Giter Site logo

sidekiq-cancellable-worker's Introduction

Sidekiq::CancellableWorker

This gem allows Sidekiq workers to cancel themselves at runtime. Using long-running Sidekiq jobs that perform some kind of long computation (which is also better to avoid), you might want to be able to cancel these jobs in a clean and controlled way.

Usage

class MyWorker
  include Sidekiq::Worker
  prepend Sidekiq::CancellableWorker

  def perform(args = {})
    # perform some long running work
    100.times do |i|
      sleep i
      return if @context.cancelled?
    end
  end
end

Then, while it is running, the job can be cancelled this way (for example in the Rails console):

MyWorker.cancel!(jid)

Prepending the module Sidekiq::Cancellable worker injects the @context variable into the worker at runtime. The worker can then call @context.cancelled? (or pass it through the chain of execution) to be able to stop the execution depending on the result.

Installation

Add this line to your application's Gemfile:

gem 'sidekiq-cancellable-worker'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sidekiq-cancellable-worker

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/OnceApp/sidekiq-cancellable-worker.

License

The gem is available as open source under the terms of the MIT License.

sidekiq-cancellable-worker's People

Contributors

leoht avatar

Stargazers

Rodolfo avatar

Watchers

James Cloos avatar  avatar

Forkers

edgarv09

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.