Git Product home page Git Product logo

paper_trail-background.rb's Introduction

paper_trail-background

Allows you to enqueue version creation/deletion as a background job to avoid having business logic blocked by changelog writing.

Using

First you'll need to setup a job for processing versions:

# The class MUST be named this
class VersionJob < ApplicationJob
  queue_as :default

  # This wires up the background job
  include PaperTrail::Background::Job
end

Configuration

In an initializer, you can specify whether you want to opt into this behavior on a per-model basis:

PaperTrail::Background::Config.configure do |config|
  config.opt_in = true
end

If opt-in behavior is set to true, you can enable async paper trails by specifying async: true in a given model's paper trail options:

class SomeModel < ActiveRecord::Base
  has_paper_trail async: true
end

Installing

Run this command in your project:

$ bundle add paper_trail-background

Or install it yourself with:

$ gem install paper_trail-background

Contributing

  1. Read the Code of Conduct
  2. Fork it
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

Todo

  • Support other job types
  • Allow for configuring the job class name

paper_trail-background.rb's People

Contributors

bwilkins avatar caelanpthomas avatar coorasse avatar erf530 avatar krainboltgreene avatar stevenelberger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

paper_trail-background.rb's Issues

Gemspec Homepage

FYI, the homepage listed in the gemspec gives a 404.

I assume you wanted: https://github.com/krainboltgreene/paper_trail-background.rb ?

Is it suitable with sidekiq-unique-jobs?

In Installation instruction, in VersionJob you suggested:

  # These are settings you'll probably want, I suggest sidekiq-unique-jobs
  sidekiq_options(
    :queue => "versions",
    :unique_across_queues => true,
    :lock => :until_executed,
    :log_duplicate_payload => true
  )

While in the sidekiq-unique-jobs gem, they clearly state that they haven't support for ActiveJob https://github.com/mhenrixon/sidekiq-unique-jobs/wiki/About-ActiveJob, is it this gem: https://github.com/mhenrixon/sidekiq-unique-jobs/ you are mentioning in the installation guide?

Moreover, sidekiq_options is also only available in Sidekiq::Worker, so when I used your code, it raised this exception:

NoMethodError:
  undefined method `sidekiq_options' for VersionJob:Class
  Did you mean?  sidekiq_delay_until

Many thanks,

didn't detect the roll back

there is an issue that if there is an exception occurs during the after_save callback this will cause a rollback and the record will get removed but the version job is created and gets stuck as it tries to find a non-existing record, how should i solve this issue

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.