Git Product home page Git Product logo

dj_remixes's Introduction

DJ Remixes

A boat load of incredibly useful ‘plugins’ for Delayed::Job! DJ is a wonderful project and is incredibly useful, however it can be even more useful with just a few extras added in.

The Extras

  • A proper ‘Worker’ class: DJ::Worker that accepts attributes.
  • Callbacks
  • Airbrake (Hoptoad) support, if using Airbrake.
  • Priority settings
  • Automatic re-enqueueing
  • Better scheduling
  • Unique jobs.
  • more …

These are a few of the extras for DJ that are included here.

Installation

In your Gemfile add the following:


  gem "delayed_job", "2.1.4"
  gem "dj_remixes"

Then install the gems:


  $ bundle install

Create a migration to add the required dj_remixes fields to the delayed_job table:


  class AddDjRemixesColumns < ActiveRecord::Migration
    def self.up
      add_column :delayed_jobs, :worker_class_name,   :string
      add_column :delayed_jobs, :started_at,          :datetime
      add_column :delayed_jobs, :finished_at,         :datetime
    end

    def self.down
      remove_column :delayed_jobs, :worker_class_name
      remove_column :delayed_jobs, :started_at
      remove_column :delayed_jobs, :finished_at
    end
  end

Using

Basic Worker


  class FooWorker < DJ::Worker
  
    def perform
      # do work
    end
  
  end
  
  FooWorker.enqueue

Unique Worker

Tell DJ to only allow one of this worker at a given time.


  # We only want to charge the card once!
  class PurchaseWorker < DJ::Worker
    is_unique
  
    def perform
      # charge the credit card...
    end
  end

If the worker has an id attribute that then will be used in conjunction with the class name of the worker to form the unique key.

Priority

Tell DJ to run this worker with a higher priority than others.


  class FooWorker < DJ::Worker
    priority :high
  
    def perform
      # do work
    end
  
  end
  
  FooWorker.enqueue

Re-Enqueueing

Tell DJ to re-enqueue this worker after it has successfully completely. NOTE: This will actually create a new DJ object in the database, not reuse the same one.


  # Run every 30 days and charge a credit card.
  class SubscriptionWorker < DJ::Worker
    re_enqueue

    def run_at
      30.days.from_now
    end

    def perform
      # charge the credit card...
    end
  end

Attributes

The DJ::Worker class can accept attributes, similar to the way an ActiveRecord model can.


  class FooWorker < DJ::Worker
    priority :high
  
    def perform
      # do work
      puts self.id # => 1
      puts self.person # => 'Mark Bates'
    end
  
  end
  
  worker = FooWorker.new(:id => 1, :person => 'Mark Bates')
  worker.enqueue!

Contributors

  • Mark Bates
  • Stuart Garner
  • Brent Kirby
  • Luke Pearce
  • Lars Pindrake

dj_remixes's People

Contributors

brentkirby avatar calvincorreli avatar kule avatar markbates avatar

Stargazers

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

Watchers

 avatar  avatar

dj_remixes's Issues

does this work with the simple .delay. syntax?

I'm not using Delayed::Job.enqueue but rather simply object.delay.method which works fine in my case. I don't see AirBrake being called in this case. Not a big deal if I have to change my code to Delayed::Job.enqueue but just wanted to know if this is a Bug or not.

emails being handled by DJ::MailManWorker instead of Delayed::Worker

I am using remixes with the current master branch of DJ (though was using the most recent release > 2.1 but trying to fix the issues). When sending mail I keep getting a undefined method "worker_class_name=" for Delayed::Backend::ActiveRecord.

I am using normal DelayedJob for one off emails but was setting up remixes to handle recurring email jobs and a few other tasks. When DelayedJob fails to run its task, the actual error logged is that I am missing the "started_at" column in my delayed_jobs table. I couldn't find any sort of migration in remixes or DJ that added this field, so I'm not sure if thats really the issue, or if that is what DelayedJob is assuming it is.

One question I have is are you able to continue to use DelayedJob normally once adding Remixes? It seems like remixes is overriding everything. My email jobs are actually being created using the remixes MailManWorker (as identified by the handler in my DJ table) leading me to believe DJ is being skipped completely and MailManWorker is taking over the job.

That being said the entire problem could be that I need to be using an official "Job" (subclassing DJ::Worker), but it seemed to me that Remixes was more of an addon where I could still use DJ as normal outside of it.

Any thoughts or ideas? Thanks!

rake jobs:work stalls

Hiya Mark,

Please close this but thought I'd note this down in case someone else has the same issue as me:

Using OSX stock ruby 1.8.7 & the recommended delayed_job 2.1.1 - when I ran rake jobs:work it wouldn't actually start the job worker or process any jobs - it just seemed to hang on the command line.

Upgrading to delayed_job 2.1.4 fixed the issue for me and re_enqueuing seems to work great now.

Cheers
Luke

'bundle console' fails

I would like to use 'bundle console' to start an IRB session in the context of my current bundle, which includes dj_remixes. However, bundle console won't load due to uninitialized constant errors. I got it working with some if defined? Rails conditionals to the definitions of DJ::ActiveRecordRailtie and DJ::ActionMailerRailtie in their initializers, but I'm not sure that's the right way to do it.

$ bundle console
/.../vendor/ruby/1.9.1/gems/dj_remixes-0.3.0/lib/dj_remixes/active_record_railtie.rb:2:in `<module:DJ>': uninitialized constant DJ::Rails (NameError)

$ bundle console
/.../vendor/ruby/1.9.1/gems/dj_remixes-0.3.0/lib/dj_remixes/action_mailer/action_mailer_railtie.rb:2:in `<module:DJ>': uninitialized constant DJ::Rails (NameError)

Can't get re_enqueue to work

Hi
dj_remixes is just what I'm looking for, but I can't get it to work ...
I have added it to the Gemfile, and created a lib/feed_updater.rb. Ran the generator, and ran script/delayed_job start
Then I opened the rails console, required feed_updater and enqueued it. It run after a minute, but then it disappears from the table, it's not readded.
When I tried to enqueue it the first time, worker_class_name and finished_at was missing from the database. I added them as string and datetime.

This is my current class:

class UpdateFeeds < DJ::Worker
  re_enqueue

  def run_at
    1.minute.from_now
  end

  def perform
    puts "HELLO!!"
  end
end

Have I missed some steps?

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.