From fe24b435b37edae94b32e18b6e34bcb07f3edd43 Mon Sep 17 00:00:00 2001 From: Dzmitry Plashchynski Date: Fri, 6 Mar 2015 23:57:55 +0200 Subject: [PATCH] Save job on every perform --- lib/crono/job.rb | 1 + spec/job_spec.rb | 6 ++++++ spec/orm/active_record/crono_job_spec.rb | 5 ----- spec/spec_helper.rb | 5 +++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/crono/job.rb b/lib/crono/job.rb index ba67828..c7081a2 100644 --- a/lib/crono/job.rb +++ b/lib/crono/job.rb @@ -25,6 +25,7 @@ module Crono def perform logger.info "Perform #{performer}" self.last_performed_at = Time.now + save Thread.new do performer.new.perform logger.info "Finished #{performer} in %.2f seconds" % (Time.now - last_performed_at) diff --git a/spec/job_spec.rb b/spec/job_spec.rb index a160264..7fdecda 100644 --- a/spec/job_spec.rb +++ b/spec/job_spec.rb @@ -18,6 +18,12 @@ describe Crono::Job do thread = job.perform.join expect(thread).to be_stop end + + it "should call Job#save after run" do + expect(job).to receive(:save) + job.perform.join + job.send(:model).destroy + end end describe "#description" do diff --git a/spec/orm/active_record/crono_job_spec.rb b/spec/orm/active_record/crono_job_spec.rb index 0110588..8379a6d 100644 --- a/spec/orm/active_record/crono_job_spec.rb +++ b/spec/orm/active_record/crono_job_spec.rb @@ -1,9 +1,4 @@ require "spec_helper" -require "generators/crono/install/templates/migrations/create_crono_jobs.rb" - -ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') -ActiveRecord::Base.logger = Logger.new(STDOUT) -CreateActiveAdminComments.up describe Crono::CronoJob do let(:valid_attrs) do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index eb258ee..e331f34 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,11 @@ Bundler.setup require 'timecop' require 'crono' +require 'generators/crono/install/templates/migrations/create_crono_jobs.rb' + +ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') +ActiveRecord::Base.logger = Logger.new(STDOUT) +CreateActiveAdminComments.up RSpec.configure do |config| end