Add CLI#run_job

This commit is contained in:
Dzmitry Plashchynski
2015-03-03 14:36:00 +02:00
parent 5efd2681d0
commit 2c78115ce7
3 changed files with 24 additions and 2 deletions

View File

@@ -7,8 +7,10 @@ module Crono
def run def run
load_rails load_rails
print_banner print_banner
# start_working_loop
end end
private
def print_banner def print_banner
puts "Loading Crono #{Crono::VERSION}" puts "Loading Crono #{Crono::VERSION}"
puts "Running in #{RUBY_DESCRIPTION}" puts "Running in #{RUBY_DESCRIPTION}"
@@ -19,5 +21,15 @@ module Crono
require File.expand_path("config/environment.rb") require File.expand_path("config/environment.rb")
::Rails.application.eager_load! ::Rails.application.eager_load!
end end
def run_job(klass)
Thread.new { klass.new.perform }
end
def start_working_loop
Config.instance.schedule.each do |klass, period|
run_job(klass)
end
end
end end
end end

View File

@@ -1,6 +1,10 @@
require "spec_helper" require "spec_helper"
require 'crono/cli' require 'crono/cli'
class TestJob
def perform;end
end
describe Crono::CLI do describe Crono::CLI do
let(:cli) { Crono::CLI.instance } let(:cli) { Crono::CLI.instance }
@@ -10,4 +14,11 @@ describe Crono::CLI do
cli.run cli.run
end end
end end
describe "#run_job" do
it "should run job in separate thread" do
thread = cli.send(:run_job, TestJob).join
expect(thread).to be_stop
end
end
end end

View File

@@ -1,7 +1,6 @@
require "spec_helper" require "spec_helper"
require "active_job"
class TestJob < ActiveJob::Base class TestJob
def perform;end def perform;end
end end