mirror of
https://github.com/plashchynski/crono.git
synced 2026-04-25 10:18:49 +02:00
add config class and schedule
This commit is contained in:
@@ -4,7 +4,7 @@ end
|
||||
require "active_support/all"
|
||||
require "periodicity/version.rb"
|
||||
require "periodicity/period.rb"
|
||||
|
||||
require "periodicity/config.rb"
|
||||
require 'periodicity/extensions/active_job'
|
||||
require "periodicity/rails.rb" if defined?(::Rails::Engine)
|
||||
require "periodicity/cli.rb"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
module Periodicity
|
||||
class Cli
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
11
lib/periodicity/config.rb
Normal file
11
lib/periodicity/config.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
module Periodicity
|
||||
class Config
|
||||
include Singleton
|
||||
|
||||
attr_accessor :schedule
|
||||
|
||||
def initialize
|
||||
self.schedule = []
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,7 +2,7 @@ module Periodicity
|
||||
module Extensions
|
||||
module ActiveJob
|
||||
def perform_every(period, *args)
|
||||
@period = Period.new(period, *args)
|
||||
Config.instance.schedule += [self, Period.new(period, *args)]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
10
spec/config_spec.rb
Normal file
10
spec/config_spec.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe Periodicity::Config do
|
||||
describe "#initialize" do
|
||||
it "should initialize schedule with an empty array" do
|
||||
@config = Periodicity::Config.instance
|
||||
expect(@config.schedule).to eql([])
|
||||
end
|
||||
end
|
||||
end
|
||||
16
spec/extensions/active_job_spec.rb
Normal file
16
spec/extensions/active_job_spec.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
require "spec_helper"
|
||||
|
||||
class TestJob < ActiveJob::Base
|
||||
def perform;end
|
||||
end
|
||||
|
||||
TestJob.extend(Periodicity::Extensions::ActiveJob)
|
||||
|
||||
describe Periodicity::Extensions::ActiveJob do
|
||||
describe "#perform_every" do
|
||||
it "should add job and period to schedule" do
|
||||
TestJob.perform_every(1.second)
|
||||
expect(Periodicity::Config.instance.schedule).to_not be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,7 @@
|
||||
require 'bundler/setup'
|
||||
Bundler.setup
|
||||
|
||||
require 'active_job'
|
||||
require 'timecop'
|
||||
require 'periodicity'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user