Refactoring

This commit is contained in:
Dzmitry Plashchynski
2015-03-10 23:46:07 +02:00
parent 6859d1f09a
commit 46fe2548d9
2 changed files with 18 additions and 16 deletions

View File

@@ -11,7 +11,7 @@ Crono is a time-based background job scheduler daemon (just like Cron) for Ruby
## The Idea
Currently there is no such thing as Cron in Ruby for Rails. Well, there's [Whenever](https://github.com/javan/whenever) but it works on top of Unix Cron, so you have no total control of it from Ruby. Crono is pure Ruby. It doesn't use Unix Cron and other platform-dependent things. So you can use it on all platforms supported by Ruby. It persists job state to your database using Active Record. You have full control of jobs performing process. You have Ruby code, so you can understand and modify it to fit your needs.
Currently there is no such thing as Ruby Cron for Rails. Well, there's [Whenever](https://github.com/javan/whenever) but it works on top of Unix Cron, so you have no total control of it from Ruby. Crono is pure Ruby. It doesn't use Unix Cron and other platform-dependent things. So you can use it on all platforms supported by Ruby. It persists job state to your database using Active Record. You have full control of jobs performing process. You have Ruby code, so you can understand and modify it to fit your needs.
![Web UI](https://github.com/plashchynski/crono/raw/master/examples/crono_web_ui.png)
@@ -26,7 +26,7 @@ Other versions are untested but might work fine.
Add the following line to your application's Gemfile:
```ruby
gem 'crono'
gem 'crono', require: false
```
Run the `bundle` command to install it.

View File

@@ -31,20 +31,7 @@ module Crono
log "Perform #{performer}"
self.last_performed_at = Time.now
Thread.new do
begin
performer.new.perform
rescue Exception => e
log "Finished #{performer} in %.2f seconds with error: #{e.message}" % (Time.now - last_performed_at)
log e.backtrace.join("\n")
self.healthy = false
else
self.healthy = true
log "Finished #{performer} in %.2f seconds" % (Time.now - last_performed_at)
ensure
save
end
end
Thread.new { perform_job }
end
def save
@@ -61,6 +48,21 @@ module Crono
end
private
def perform_job
begin
performer.new.perform
rescue Exception => e
log "Finished #{performer} in %.2f seconds with error: #{e.message}" % (Time.now - last_performed_at)
log e.backtrace.join("\n")
self.healthy = false
else
self.healthy = true
log "Finished #{performer} in %.2f seconds" % (Time.now - last_performed_at)
ensure
save
end
end
def log(message)
@semaphore.synchronize do
logger.info message