Entries Tagged 'plugins' ↓

administrate_me 2: we’re almost there!

As you well know administrate_me is our beloved plugin, and it’s about to reach its two years old (and one amazing year since we opensourced it). We never stop using it and I believe that’s the main reason why this plugin has grown that much this year.

With administrate_me, we’re able to build a production-ready backend in a couple of minutes. It simplifies almost any management task you need to build for a rails app, this way you can focus and put all your efforts into application’s frontend.

We’re almost done with administrate_me 2.0 version (I believe its release will be on or about December 18th), you can watch plugin’s progress on github (even you can push some patches).

For those who can’t wait til December 18th, here you have a little snapshot of administrate_me’s backend new look

We’re definately there! yay!

backup_fu on Windows

backup_fu is a nice Rails plugin to backup all your data to an S3 account. Sadly, it currently doesn’t work on windows.

Two bugs prevent it to run smoothly, first it depends on tar and gzip commands, which are not always available on that platform. Even though there are some native implementations, I’ve never found a tar one that I could actually use, most of them just fail at archiving big files. I’ve fixed this using the minitar gem to generate a tar.gz file from the sql dump.

On the other hand, there is an aws-s3 bug that prevents files to be directly passed to the store() method to upload the files. Fixing this was just a matter to read the file using ‘rb’ parameters for File.open().

You can see this and this commit with the changes, a pull request has already been sent.

Playing with delayed_job plugin

The need for executing long task process is a common thing in large-scale rails projects these days. This is something any serious developer should be aware of. Make no mistake, long tasks can consume large amounts of servers resources, and they can provoke servers to crash when you request them via http.

A great solution for this problem is the delayed_job plugin by Tobias Lütke. This plugin is very easy to install, is very well documented, and provides you with everything you’ll need to execute task in background. I had the oportunity to try it out on burdastyle.com, and it worked just fine. So, congratulations Tobi for this great work and thanks for sharing.

So, let’s try delayed_job plugin out.

First thing we need to do after we install this plugin is to generate a migration to add delayed_jobs table into our database. This migration should look like this:

class CreateDelayedJobs < ActiveRecord::Migration
  def self.up
    create_table :delayed_jobs, :force => true do |table|
      table.integer  :priority, :default => 0
      table.integer  :attempts, :default => 0
      table.text     :handler
      table.string   :last_error
      table.datetime :run_at
      table.datetime :locked_at
      table.datetime :failed_at
      table.string   :locked_by
      table.timestamps
    end
  end

  def self.down
  end
end

Then, we’ll need to define our jobs. A job is just a ruby class with a method called perform. Let’s say we need to send a very simple email notification to our entire users database. We can use this little class:

class NotificationJob < Struct.new(:message)
  def perform
    total = User.count
    limit = 100
    (0..total-1).step(limit) do |offset|
       User.find(:all, :limit => limit, :offset => offset).each do |u|
         Notifier.deliver_message_to_user(u, message)
       end
    end
  end
end

Now, every time you need to send these notifications out, you just enqueue your job like this:

Delayed::Job.enqueue NotificationJob.new("hello world!")

Finally, delayed_job plugin provides you with a set of rake tasks to put enqueue jobs to work:

rake jobs:work

And that’s all folks! Have fun with delayed_job.

Happy hacking!