GithubHelp home page GithubHelp logo

active_job_exception_handler's Introduction

ActiveJobExceptionHandler

Gem Version

Table of Contents

Features

Screencasts

Requirements

  1. Ruby 2.4.1

Setup

For a secure install, type the following (recommended):

gem cert --add <(curl --location --silent /gem-public.pem)
gem install active_job_exception_handler --trust-policy MediumSecurity

NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification while allowing the installation of unsigned dependencies since they are beyond the scope of this gem.

For an insecure install, type the following (not recommended):

gem install active_job_exception_handler

Add the following to your Gemfile:

gem "active_job_exception_handler"

Usage

Initialize it like this:

class ApplicationJob < ActiveJob::Base

  before_perform :initialize_exception_handler

  def perform(normal:, credentials: {}, spawn_job_id:, exception_handler: default_exception_handler)
    @exception_handler = exception_handler
    initialize_exception_handling

    exception_handler.process! do
      return if skip?
      collector.run run_options
      emitter.flush!
      kapost_client.update_credentials(adapter.updated_tokens) if adapter.refreshed_tokens?
      perform_successful
    end
  end

  protected

  def exception_handler
    @exception_handler ||= ExceptionHandler.new(exception_context: exception_context)
  end

  def exception_context
    ExceptionContext.new(
      source: self.class.name,
      queue: queue_name,
      args: arguments
    )
  end

  def initialize_exception_handling
    # implement this method to define how errors are handled
  end
end

And then use it in jobs like this:

class MyJob < ApplicationJob

  def perform(...)
    # ...
  end

  protected

  def initialize_exception_handling
    exception_handler.add HTTPServerError, :retryables # Transient HTTP error
    exception_handler.add HTTPAuthenticationError, :unretryables # User credentials are wrong, don't retry
    exception_handler.add HTTPNotFoundError, :ignorables # Page is gone, we don't care anymore
  end

end

Tests

To test, run:

bundle exec rake

Versioning

Read Semantic Versioning for details. Briefly, it means:

  • Major (X.y.z) - Incremented for any backwards incompatible public API changes.
  • Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
  • Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.

Code of Conduct

Please note that this project is released with a CODE OF CONDUCT. By participating in this project you agree to abide by its terms.

Contributions

Read CONTRIBUTING for details.

License

Copyright (c) 2017 . Read LICENSE for details.

History

Read CHANGES for details. Built with Gemsmith.

Credits

Developed by Paul Sadauskas and Brooke Kuhlmann at Kapost.

active_job_exception_handler's People

Contributors

paul avatar

Watchers

 avatar  avatar

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.