mirror of
https://github.com/plashchynski/crono.git
synced 2026-04-20 16:01:30 +02:00
Add migration to generator
This commit is contained in:
@@ -31,7 +31,7 @@ After you install Crono, you can run the generator:
|
|||||||
|
|
||||||
rails generate crono:install
|
rails generate crono:install
|
||||||
|
|
||||||
It will create a configuration file `config/cronotab.rb`
|
It will create a configuration file `config/cronotab.rb` and migration
|
||||||
Now you are ready to move forward to create a job and schedule it.
|
Now you are ready to move forward to create a job and schedule it.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
|||||||
require "crono/cli"
|
require "crono/cli"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
cli = Crono::CLI.instance
|
Crono::CLI.instance.run
|
||||||
cli.run
|
|
||||||
rescue => e
|
rescue => e
|
||||||
raise e if $DEBUG
|
raise e if $DEBUG
|
||||||
STDERR.puts e.message
|
STDERR.puts e.message
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ module Crono
|
|||||||
"Perform #{performer} #{period.description}"
|
"Perform #{performer} #{period.description}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def job_id
|
||||||
|
description
|
||||||
|
end
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
logger.info "Perform #{performer}"
|
logger.info "Perform #{performer}"
|
||||||
self.last_performed_at = Time.now
|
self.last_performed_at = Time.now
|
||||||
|
|||||||
@@ -1,12 +1,26 @@
|
|||||||
|
require 'rails/generators'
|
||||||
|
require 'rails/generators/migration'
|
||||||
|
require 'rails/generators/active_record'
|
||||||
|
|
||||||
module Crono
|
module Crono
|
||||||
module Generators
|
module Generators
|
||||||
class InstallGenerator < ::Rails::Generators::Base
|
class InstallGenerator < ::Rails::Generators::Base
|
||||||
|
include Rails::Generators::Migration
|
||||||
|
|
||||||
|
def self.next_migration_number(path)
|
||||||
|
ActiveRecord::Generators::Base.next_migration_number(path)
|
||||||
|
end
|
||||||
|
|
||||||
desc "Installs crono and generates the necessary configuration files"
|
desc "Installs crono and generates the necessary configuration files"
|
||||||
source_root File.expand_path("../templates", __FILE__)
|
source_root File.expand_path("../templates", __FILE__)
|
||||||
|
|
||||||
def copy_config
|
def copy_config
|
||||||
template 'cronotab.rb.erb', 'config/cronotab.rb'
|
template 'cronotab.rb.erb', 'config/cronotab.rb'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_migrations
|
||||||
|
migration_template 'migrations/create_crono_jobs.rb', 'db/migrate/create_crono_jobs.rb'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
class CreateActiveAdminComments < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
create_table :crono_jobs do |t|
|
||||||
|
t.string :job_id, null: false
|
||||||
|
t.text :log
|
||||||
|
t.datetime :last_performed_at
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :crono_jobs, [:job_id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
drop_table :crono_jobs
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user