mirror of
https://github.com/plashchynski/crono.git
synced 2026-11-16 13:41:06 +01:00
Add CLI#run_job
This commit is contained in:
1 parent
5efd2681d0
commit
2c78115ce7
3 files changed
+24
-2
No files matched your search
@@ -7,8 +7,10 @@ module Crono
|
||||
def run
|
||||
load_rails
|
||||
print_banner
|
||||
# start_working_loop
|
||||
end
|
||||
|
||||
private
|
||||
def print_banner
|
||||
puts "Loading Crono #{Crono::VERSION}"
|
||||
puts "Running in #{RUBY_DESCRIPTION}"
|
||||
@@ -19,5 +21,15 @@ module Crono
|
||||
require File.expand_path("config/environment.rb")
|
||||
::Rails.application.eager_load!
|
||||
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
|
||||
@@ -1,6 +1,10 @@
|
||||
require "spec_helper"
|
||||
require 'crono/cli'
|
||||
|
||||
class TestJob
|
||||
def perform;end
|
||||
end
|
||||
|
||||
describe Crono::CLI do
|
||||
let(:cli) { Crono::CLI.instance }
|
||||
|
||||
@@ -10,4 +14,11 @@ describe Crono::CLI do
|
||||
cli.run
|
||||
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
|
||||
@@ -1,7 +1,6 @@
|
||||
require "spec_helper"
|
||||
require "active_job"
|
||||
|
||||
class TestJob < ActiveJob::Base
|
||||
class TestJob
|
||||
def perform;end
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user