quartz-jruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ === 0.1.0 2010-12-01
2
+
3
+ * Basic cron ability with java quartz
4
+ * Initial release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010, Vagmi Mudumbai
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,14 @@
1
+ History.txt
2
+ LICENSE
3
+ Manifest.txt
4
+ README.markdown
5
+ Rakefile
6
+ lib/quartz.rb
7
+ lib/quartz/cron_job.rb
8
+ lib/quartz/cronify.rb
9
+ lib/quartz/job_detail.rb
10
+ lib/quartz/job_factory.rb
11
+ lib/quartz/scheduler.rb
12
+ lib/quartz/version.rb
13
+ test/test_helper.rb
14
+ test/test_quartz-jruby.rb
@@ -0,0 +1,42 @@
1
+ ## Quartz for JRuby
2
+
3
+ From [Quartz Scheduler's website](http://www.quartz-scheduler.org/)
4
+
5
+ > Quartz is a full-featured, open source job scheduling service that can be integrated with, or used along side virtually any Java EE or Java SE application - from the smallest stand-alone application to the largest e-commerce system. Quartz can be used to create simple or complex schedules for executing tens, hundreds, or even tens-of-thousands of jobs; jobs whose tasks are defined as standard Java components that may executed virtually anything you may program them to do. The Quartz Scheduler includes many enterprise-class features, such as JTA transactions and clustering.
6
+
7
+
8
+ ## Usage
9
+
10
+ class TestScheduler
11
+ include Quartz::Scheduler
12
+ schedule(:say_hello_5, :every=>5.seconds) { info "every 5 seconds" }
13
+ schedule(:say_hello_30, :every=>30.seconds) { error "every 30 seconds" }
14
+ end
15
+ TestScheduler.instance.run
16
+
17
+ ## Feedback
18
+
19
+ If you have any feedback, send me an email vagmi <at> [artha42.com](http://www.artha42.com).
20
+
21
+ ## License
22
+
23
+ Copyright (c) 2010, Vagmi Mudumbai
24
+
25
+ Permission is hereby granted, free of charge, to any person obtaining
26
+ a copy of this software and associated documentation files (the
27
+ 'Software'), to deal in the Software without restriction, including
28
+ without limitation the rights to use, copy, modify, merge, publish,
29
+ distribute, sublicense, and/or sell copies of the Software, and to
30
+ permit persons to whom the Software is furnished to do so, subject to
31
+ the following conditions:
32
+
33
+ The above copyright notice and this permission notice shall be
34
+ included in all copies or substantial portions of the Software.
35
+
36
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
37
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
38
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
39
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
40
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
41
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
42
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/quartz/version'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'quartz-jruby' do
14
+ self.readme_file = 'quartz-jruby.rdoc'
15
+ self.version = Quartz::VERSION
16
+ self.developer 'Vagmi Mudumbai', 'vagmi@artha42.com'
17
+ self.rubyforge_name = self.name # TODO this is default value
18
+ self.extra_deps = [['activesupport','>= 3.0.3']]
19
+
20
+ end
21
+
22
+ require 'newgem/tasks'
23
+ Dir['tasks/**/*.rake'].each { |t| load t }
24
+
25
+ # TODO - want other tests/tasks run by default? Add them to the list
26
+ # remove_task :default
27
+ # task :default => [:spec, :features]
@@ -0,0 +1,14 @@
1
+ require 'java'
2
+ $:.unshift(File.dirname(__FILE__)) unless
3
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
4
+
5
+ require 'rubygems'
6
+ require 'singleton'
7
+ require 'active_support'
8
+ require 'quartz/version'
9
+ require 'quartz/job_factory'
10
+ require 'quartz/job_detail'
11
+ require 'quartz/cron_job'
12
+ require 'quartz/cronify'
13
+ require 'quartz/scheduler'
14
+
@@ -0,0 +1,15 @@
1
+ require 'java'
2
+ import org.quartz.Job
3
+ module Quartz
4
+ class CronJob
5
+ include org.quartz.Job
6
+ attr_accessor :name
7
+ def initialize(name)
8
+ @name=name
9
+ end
10
+ def execute(context)
11
+ job_block = JobFactory.instance.jobs[@name]
12
+ job_block.call
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
4
+
5
+ # this stuff is based on whenver
6
+ # https://github.com/javan/whenever/
7
+
8
+ module Quartz
9
+ class Cronify
10
+ def self.comma_separated_timing(frequency, max, start = 0)
11
+ return start if frequency.blank? || frequency.zero?
12
+ return frequency if frequency > (max * 0.5).ceil
13
+
14
+ original_start = start
15
+
16
+ start += frequency unless (max + 1).modulo(frequency).zero? || start > 0
17
+ output = (start..max).step(frequency).to_a
18
+
19
+ max_occurances = (max.to_f / (frequency.to_f)).round
20
+ max_occurances += 1 if original_start.zero?
21
+
22
+ output[0, max_occurances].join(',')
23
+ end
24
+
25
+
26
+ def self.cronify(time,at=0)
27
+ timing = %w(0 * * * * ?)
28
+ case time
29
+ when 0.seconds...1.minute
30
+ timing[0] = "0/#{time.to_s}"
31
+ when 1.minute...1.hour
32
+ minute_frequency = time / 60
33
+ timing[1] = comma_separated_timing(minute_frequency, 59, at || 0)
34
+ when 1.hour...1.day
35
+ hour_frequency = (time / 60 / 60).round
36
+ timing[1] = at.is_a?(Time) ? at.min : at
37
+ timing[2] = comma_separated_timing(hour_frequency, 23)
38
+ when 1.day...1.month
39
+ day_frequency = (time / 24 / 60 / 60).round
40
+ timing[1] = at.is_a?(Time) ? at.min : 0
41
+ timing[2] = at.is_a?(Time) ? at.hour : at
42
+ timing[3] = comma_separated_timing(day_frequency, 31, 1)
43
+ when 1.month..12.months
44
+ month_frequency = (time / 30 / 24 / 60 / 60).round
45
+ timing[1] = at.is_a?(Time) ? at.min : 0
46
+ timing[2] = at.is_a?(Time) ? at.hour : 0
47
+ timing[3] = at.is_a?(Time) ? at.day : (at.zero? ? 1 : at)
48
+ timing[4] = comma_separated_timing(month_frequency, 12, 1)
49
+ else
50
+ return 'bummer'
51
+ end
52
+ timing.join(' ')
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,13 @@
1
+ module Quartz
2
+ class JobDetail < Java::OrgQuartz::JobDetail
3
+ attr_accessor :job
4
+ def initialize(name,group,job)
5
+ super()
6
+ set_name name
7
+ set_group group
8
+ @job = job
9
+ end
10
+ def validate
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module Quartz
2
+ class JobFactory
3
+ include Singleton
4
+ include org.quartz.spi.JobFactory
5
+ attr_accessor :jobs
6
+ def initialize
7
+ @jobs||={}
8
+ end
9
+ def new_job(event)
10
+ event.get_job_detail.job
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,66 @@
1
+ require 'java'
2
+
3
+ # java quartz imports
4
+ import org.quartz.CronTrigger
5
+ import org.quartz.impl.StdSchedulerFactory
6
+
7
+
8
+ module Quartz
9
+ module Scheduler
10
+
11
+ def self.included(base)
12
+ base.class_eval <<-EOF
13
+ include InstanceMethods
14
+ extend ClassMethods
15
+ include Singleton
16
+ EOF
17
+ end
18
+
19
+ module ClassMethods
20
+ def schedule(name,options,&block)
21
+ instance.schedule(name,options,block)
22
+ end
23
+ def log
24
+ org.apache.log4j.Logger.get_logger(self.name)
25
+ end
26
+ def info(msg)
27
+ log.log(org.apache.log4j.Level::INFO,msg)
28
+ end
29
+ def error(msg)
30
+ log.log(org.apache.log4j.Level::ERROR,msg)
31
+ end
32
+ def warn(msg)
33
+ log.log(org.apache.log4j.Level::WARN,msg)
34
+ end
35
+ end
36
+
37
+ module InstanceMethods
38
+ def schedule(name, options, block)
39
+ options=defaults.merge options
40
+ job_factory.jobs[name.to_s] = block
41
+ job_detail = JobDetail.new(name.to_s, "cronjob",CronJob.new(name.to_s))
42
+ cron_expression = Cronify.cronify(options[:every],options[:at])
43
+ trigger=CronTrigger.new("#{name.to_s}_crontrig","cront_trig_group",name.to_s,"cronjob",cron_expression)
44
+ scheduler.set_job_factory(job_factory)
45
+ scheduler.schedule_job(job_detail,trigger)
46
+ end
47
+ def defaults
48
+ {
49
+ :at=>0
50
+ }
51
+ end
52
+ def scheduler_factory
53
+ @scheduler_factor ||= StdSchedulerFactory.new
54
+ end
55
+ def scheduler
56
+ scheduler_factory.get_scheduler
57
+ end
58
+ def job_factory
59
+ JobFactory.instance
60
+ end
61
+ def run
62
+ scheduler.start
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module Quartz
2
+ VERSION="0.1.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'stringio'
2
+ #require 'test/unit'
3
+
4
+ JAVA_HOME = File.expand_path(File.join(File.dirname(__FILE__),"..","java"))
5
+ JARS = Dir.glob(JAVA_HOME+"/*.jar").collect { |e| e.split(JAVA_HOME)[1].slice(1..-1) }
6
+ $:.unshift(JAVA_HOME)
7
+ JARS.each { |jar|
8
+ puts "requiring #{jar}"
9
+ require jar
10
+ }
11
+
12
+ require File.dirname(__FILE__) + '/../lib/quartz'
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ org.apache.log4j.BasicConfigurator.configure
4
+ class TestScheduler
5
+ include Quartz::Scheduler
6
+ schedule(:say_hello_5, :every=>5.seconds) { info "every 5 seconds" }
7
+ schedule(:say_hello_30, :every=>30.seconds) { error "every 30 seconds" }
8
+
9
+ end
10
+ TestScheduler.instance.run
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quartz-jruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Vagmi Mudumbai
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-02 00:00:00 +05:30
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 3
29
+ - 0
30
+ - 3
31
+ version: 3.0.3
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rubyforge
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 0
44
+ - 4
45
+ version: 2.0.4
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: hoe
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 7
58
+ - 0
59
+ version: 2.7.0
60
+ type: :development
61
+ version_requirements: *id003
62
+ description: |-
63
+ From {Quartz Scheduler's website}[http://www.quartz-scheduler.org/]
64
+
65
+ Quartz is a full-featured, open source job scheduling service that can be integrated with, or used along side virtually any Java EE or Java SE application - from the smallest stand-alone application to the largest e-commerce system. Quartz can be used to create simple or complex schedules for executing tens, hundreds, or even tens-of-thousands of jobs; jobs whose tasks are defined as standard Java components that may executed virtually anything you may program them to do. The Quartz Scheduler includes many enterprise-class features, such as JTA transactions and clustering.
66
+
67
+ This gem makes these available in a ruby friendly syntax
68
+ email:
69
+ - vagmi@artha42.com
70
+ executables: []
71
+
72
+ extensions: []
73
+
74
+ extra_rdoc_files:
75
+ - History.txt
76
+ - Manifest.txt
77
+ files:
78
+ - History.txt
79
+ - LICENSE
80
+ - Manifest.txt
81
+ - README.markdown
82
+ - Rakefile
83
+ - lib/quartz.rb
84
+ - lib/quartz/cron_job.rb
85
+ - lib/quartz/cronify.rb
86
+ - lib/quartz/job_detail.rb
87
+ - lib/quartz/job_factory.rb
88
+ - lib/quartz/scheduler.rb
89
+ - lib/quartz/version.rb
90
+ - test/test_helper.rb
91
+ - test/test_quartz-jruby.rb
92
+ has_rdoc: true
93
+ homepage: http://github.com/artha42/quartz-jruby
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options:
98
+ - --main
99
+ - quartz-jruby.rdoc
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ requirements: []
117
+
118
+ rubyforge_project: quartz-jruby
119
+ rubygems_version: 1.3.6
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: From {Quartz Scheduler's website}[http://www.quartz-scheduler.org/] Quartz is a full-featured, open source job scheduling service that can be integrated with, or used along side virtually any Java EE or Java SE application - from the smallest stand-alone application to the largest e-commerce system
123
+ test_files:
124
+ - test/test_helper.rb
125
+ - test/test_quartz-jruby.rb