lib/asynchronic/environment.rb in asynchronic-0.1.0 vs lib/asynchronic/environment.rb in asynchronic-0.2.0

- old
+ new

@@ -4,21 +4,13 @@ attr_reader :queue_engine attr_reader :data_store def initialize(queue_engine, data_store) @queue_engine = queue_engine - @data_store = data_store + @data_store = data_store.scoped :asynchronic end - def [](key) - data_store.get key - end - - def []=(key, value) - data_store.set key, value - end - def queue(name) queue_engine[name] end def default_queue @@ -27,31 +19,19 @@ def enqueue(msg, queue=nil) queue(queue || queue_engine.default_queue).push msg end - def build_job(job_class, options={}) - Asynchronic.logger.debug('Asynchronic') { "Building job #{job_class} - #{options}" } - job_class.new(options).tap do |job| - self[job.lookup.id] = job - self[job.lookup.created_at] = Time.now - end + def create_process(type, params={}) + Process.create self, type, params end - def build_process(job_class, options={}) - Process.new build_job(job_class, options), self + def load_process(id) + Process.new self, id end - - def load_process(pid) - Process.new self[pid], self - end - + def processes - data_store.keys. - select { |k| k.match Regexp.new("job:#{Asynchronic::UUID_REGEXP}:created_at$") }. - sort_by {|k| data_store.get k }. - reverse. - map { |k| load_process k.gsub(':created_at', '') } + Process.all self end end end \ No newline at end of file