Permalink
Browse files

added skeleton for couchdb

  • Loading branch information...
1 parent 69d26d4 commit 3a11cafced2ecf3610d682663e97658891a6c4b2 @rbriank rbriank committed May 4, 2010
Showing with 84 additions and 0 deletions.
  1. +84 −0 lib/delayed/backend/couch_mapper.rb
@@ -0,0 +1,84 @@
+require 'couchrest'
+
+class CouchRest::ExtendedDocument
+ def self.load_for_delayed_job(id)
+ if id
+ find(id)
+ else
+ super
+ end
+ end
+
+ def dump_for_delayed_job
+ "#{self.class};#{id}"
+ end
+end
+
+module Delayed
+ module Backend
+ module CouchRest
+
+ @@server = nil
+ @@db = nil
+
+ class Job < ::CouchRest::ExtendedDocument
+ include Delayed::Backend::Base
+ use_database ::CouchRest.db
+
+ property :priority
+ property :attempts
+ property :handler
+ property :run_at
+ property :locked_at
+ property :locked_by
+ property :failed_at
+ property :last_error
+ timestamps!
+
+ view_by :priority, :run_at
+ view_by :locked_by
+
+ save_callback :before, :set_default_run_at
+
+ def self.after_fork
+ ::CouchRest.server = CouchRest.new('http://localhost:5984')
+ ::CouchRest.db = SERVER.database!('delayed_job')
+ end
+
+ def self.db_time_now
+ Time.now.utc
+ end
+
+ def self.find_available(worker_name, limit = 5, max_run_time = Worker.max_run_time)
+
+ end
+
+ # When a worker is exiting, make sure we don't have any locked jobs.
+ def self.clear_locks!(worker_name)
+
+ end
+
+ # Lock this job for this worker.
+ # Returns true if we have the lock, false otherwise.
+ def lock_exclusively!(max_run_time, worker = worker_name)
+
+ end
+
+ def self.delete_all
+ Delayed::Job.auto_migrate!
+ end
+
+ def self.find id
+ get id
+ end
+
+ def update_attributes(attributes)
+ attributes.each do |k,v|
+ self[k] = v
+ end
+ self.save
+ end
+ end
+ end
+ end
+end

0 comments on commit 3a11caf

Please sign in to comment.