Add Job#save to save job info to DB

This commit is contained in:
Dzmitry Plashchynski
2015-03-06 23:41:03 +02:00
parent d0b35aaa6e
commit c54f52a71d
3 changed files with 26 additions and 2 deletions

View File

@@ -30,5 +30,14 @@ module Crono
logger.info "Finished #{performer} in %.2f seconds" % (Time.now - last_performed_at)
end
end
def save
model.update(last_performed_at: last_performed_at)
end
private
def model
@model ||= Crono::CronoJob.find_or_create_by(job_id: job_id)
end
end
end

View File

@@ -25,4 +25,19 @@ describe Crono::Job do
expect(job.description).to be_eql("Perform TestJob every 2 days")
end
end
describe "#save" do
it "should save new job to DB" do
expect(Crono::CronoJob.where(job_id: job.job_id)).to_not exist
job.save
expect(Crono::CronoJob.where(job_id: job.job_id)).to exist
end
it "should update saved job" do
job.last_performed_at = Time.now
job.save
@crono_job = Crono::CronoJob.find_by(job_id: job.job_id)
expect(@crono_job.last_performed_at).to be_eql(job.last_performed_at)
end
end
end

View File

@@ -8,7 +8,7 @@ CreateActiveAdminComments.up
describe Crono::CronoJob do
let(:valid_attrs) do
{
job_id: "Perform TestJob every 2 days"
job_id: "Perform TestJob every 3 days"
}
end
@@ -27,7 +27,7 @@ describe Crono::CronoJob do
it "should save job_id to DB" do
Crono::CronoJob.create!(valid_attrs)
@crono_job = Crono::CronoJob.where(job_id: valid_attrs[:job_id]).first
@crono_job = Crono::CronoJob.find_by(job_id: valid_attrs[:job_id])
expect(@crono_job).to be_present
end
end