mirror of
https://github.com/plashchynski/crono.git
synced 2026-04-23 09:18:44 +02:00
Add PerformerProxy
This commit is contained in:
@@ -5,3 +5,4 @@ require "active_support/all"
|
|||||||
require "periodicity/version.rb"
|
require "periodicity/version.rb"
|
||||||
require "periodicity/period.rb"
|
require "periodicity/period.rb"
|
||||||
require "periodicity/config.rb"
|
require "periodicity/config.rb"
|
||||||
|
require "periodicity/performer_proxy.rb"
|
||||||
15
lib/periodicity/performer_proxy.rb
Normal file
15
lib/periodicity/performer_proxy.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
module Periodicity
|
||||||
|
class PerformerProxy
|
||||||
|
def initialize(performer)
|
||||||
|
@performer = performer
|
||||||
|
end
|
||||||
|
|
||||||
|
def every(period, *args)
|
||||||
|
Config.instance.schedule += [@performer, Period.new(period, *args)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.perform(performer)
|
||||||
|
PerformerProxy.new(performer)
|
||||||
|
end
|
||||||
|
end
|
||||||
13
spec/performer_proxy_spec.rb
Normal file
13
spec/performer_proxy_spec.rb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
require "spec_helper"
|
||||||
|
require "active_job"
|
||||||
|
|
||||||
|
class TestJob < ActiveJob::Base
|
||||||
|
def perform;end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe Periodicity::PerformerProxy do
|
||||||
|
it "should add job and period to schedule" do
|
||||||
|
Periodicity.perform(TestJob).every(2.days, at: "15:30")
|
||||||
|
expect(Periodicity::Config.instance.schedule).to_not be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
require 'bundler/setup'
|
require 'bundler/setup'
|
||||||
Bundler.setup
|
Bundler.setup
|
||||||
|
|
||||||
require 'active_job'
|
|
||||||
require 'timecop'
|
require 'timecop'
|
||||||
require 'periodicity'
|
require 'periodicity'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user