trinidad_scheduler_extension 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  Trinidad Scheduler Extension
2
- ===
2
+ =========
3
3
  Trinidad Scheduler uses Quartz to schedule processes for execution. It can be run as a server extension to Trinidad and/or a Web Application extension
4
4
  for Trinidad. If run as a Server extension all schedulers will get the server configuration options each option that is defined at the Web Application
5
5
  level will override the Server option.
@@ -9,18 +9,18 @@ Trinidad Scheduler creates a unique scheduler for each web application.
9
9
  Most processes we schedule are scheduled using the *Cron* Trigger and *run_later*
10
10
 
11
11
  Install Gem
12
- ---
12
+ ---------
13
13
  gem install trinidad_scheduler_extension
14
14
 
15
15
  Configure Trinidad
16
- ---
16
+ ---------
17
17
  In either the Server *extensions* block or the Web Application *extentions* block add "scheduler"
18
18
 
19
19
  extensions:
20
20
  scheduler:
21
21
 
22
22
  Example Usage
23
- ---
23
+ ---------
24
24
  It is valid to use the top level scheduling methods and run_later together
25
25
 
26
26
  class ScheduledLog < TrinidadScheduler.Cron "0/5 * * * * ?"
@@ -34,7 +34,7 @@ It is valid to use the top level scheduling methods and run_later together
34
34
  end
35
35
 
36
36
  Laziness
37
- ---
37
+ ---------
38
38
  Trinidad Scheduler is very lazy. Schedulers will only be instantiated when they are needed to execute a job or to setup a schedule for execution.
39
39
  This laziness extends to even runtime definition of classes and use of run_later in conditional statements. When a run_later block is encountered or
40
40
  a class is defined at runtime that inherits from a TrinidadScheduler base method the scheduler will be created and started (if it does not exist)
@@ -45,13 +45,13 @@ If schedules are defined during application initialization then the scheduler wi
45
45
  is included with TrinidadScheduler)
46
46
 
47
47
  Usage
48
- ===
48
+ =========
49
49
  The extension defines several methods that return classes based on the configuration options provided. These methods map to the scheduler trigger type
50
50
  that Quartz provides. The implemented triggers are CronTrigger, SimpleTrigger, and DateIntervalTrigger.
51
51
 
52
52
  Cron Trigger
53
- ---
54
- To define a process to be run based on a [cron expression] (http://en.wikipedia.org/wiki/CRON_expression#CRON_expression)
53
+ ---------
54
+ To define a process to be run based on a [cron expression](http://en.wikipedia.org/wiki/CRON_expression#CRON_expression)
55
55
 
56
56
  class ScheduledClass < TrinidadScheduler.Cron "0/5 * * * * ?"
57
57
  def run
@@ -66,7 +66,7 @@ The instance method "run" must be defined because it is called when the schedule
66
66
  in ScheduledClass which gives the class access to the Quartz logger that is configured.
67
67
 
68
68
  Simple Trigger
69
- ---
69
+ ---------
70
70
  Schedule an INFO log message every 5 seconds starting now, setting the end is not necessary in this context, but is done
71
71
 
72
72
  class TestJob < TrinidadScheduler.Simple :start => Time.now, :end => Time.now + 240, :repeat 3, :interval => 5000
@@ -80,7 +80,7 @@ above in the example, none of them are necessary if you only want to trigger the
80
80
  times to fire the trigger along with an interval to be observed between trigger execution.
81
81
 
82
82
  DateInterval Trigger
83
- ---
83
+ ---------
84
84
  Schedule an INFO log message every 5 seconds starting now and ending after 4 minutes
85
85
 
86
86
  class TestJob < TrinidadScheduler.DateInterval :start => Time.now, :end => Time.now + 240, :unit => :second, :interval => 5
@@ -93,7 +93,7 @@ The DateInterval Trigger will execute a triggered process based on the configura
93
93
  trigger consult the source.
94
94
 
95
95
  run_later
96
- ---
96
+ ---------
97
97
  Schedules a block of code to run in another Thread after execution proceeds in the current Thread
98
98
  *after the job runs it removes itself from the job scheduler
99
99
 
@@ -109,19 +109,21 @@ Using run_later with 20 second delay
109
109
  _logger.info "I am inside this block" #=> prints "I am inside this block"
110
110
  end
111
111
 
112
- Behind the scemes *run_later* is actually implemented using an anonymous class that inherits from TrinidadScheduler.Simple to schedule the run.
112
+ Behind the scenes *run_later* is actually implemented using an anonymous class that inherits from TrinidadScheduler.Simple to schedule the run.
113
113
 
114
114
 
115
115
  Inspiration
116
- ---
116
+ ---------
117
117
  Open Source software is a community effort - thanks to all, but the following were instrumental in the inspiration for TrinidadScheduler.
118
118
 
119
- [techwhizbang] (https://github.com/techwhizbang/jruby-quartz) for handling of Quartz JobFactory
120
- [why_metaid] (https://github.com/evaryont/why_metaid) for metaid extension
121
- [TERRACOTTA] (http://www.terracotta.org/) for continued support Quartz Scheduler
122
- [calavera] (https://github.com/calavera/trinidad) for Trinidad Server
119
+ [techwhizbang](https://github.com/techwhizbang/jruby-quartz) for handling of Quartz JobFactory
123
120
 
121
+ [why_metaid](https://github.com/evaryont/why_metaid) for metaid extension
122
+
123
+ [TERRACOTTA](http://www.terracotta.org/) for continued support of Quartz Scheduler
124
+
125
+ [calavera](https://github.com/calavera/trinidad) for Trinidad Server
124
126
 
125
127
  Copyright
126
- ---
127
- Copyright (c) 2011 Brandon Dewitt<brandon+trinidad_scheduler@myjibe.com>. See LICENSE for details.
128
+ ---------
129
+ Copyright (c) 2011 Brandon Dewitt <brandon+trinidad_scheduler "at" myjibe.com>. See LICENSE for details.
data/README.rdoc ADDED
@@ -0,0 +1,127 @@
1
+ Trinidad Scheduler Extension
2
+ =========
3
+ Trinidad Scheduler uses Quartz to schedule processes for execution. It can be run as a server extension to Trinidad and/or a Web Application extension
4
+ for Trinidad. If run as a Server extension all schedulers will get the server configuration options each option that is defined at the Web Application
5
+ level will override the Server option.
6
+
7
+ Trinidad Scheduler creates a unique scheduler for each web application.
8
+
9
+ Most processes we schedule are scheduled using the *Cron* Trigger and *run_later*
10
+
11
+ Install Gem
12
+ ---------
13
+ gem install trinidad_scheduler_extension
14
+
15
+ Configure Trinidad
16
+ ---------
17
+ In either the Server *extensions* block or the Web Application *extentions* block add "scheduler"
18
+
19
+ extensions:
20
+ scheduler:
21
+
22
+ Example Usage
23
+ ---------
24
+ It is valid to use the top level scheduling methods and run_later together
25
+
26
+ class ScheduledLog < TrinidadScheduler.Cron "0/5 * * * * ?"
27
+ def run
28
+ _logger.info "Executed every 5 seconds"
29
+
30
+ TrinidadScheduler.run_later do
31
+ _logger.info "Executed after a 3 second delay"
32
+ end
33
+ end
34
+ end
35
+
36
+ Laziness
37
+ ---------
38
+ Trinidad Scheduler is very lazy. Schedulers will only be instantiated when they are needed to execute a job or to setup a schedule for execution.
39
+ This laziness extends to even runtime definition of classes and use of run_later in conditional statements. When a run_later block is encountered or
40
+ a class is defined at runtime that inherits from a TrinidadScheduler base method the scheduler will be created and started (if it does not exist)
41
+
42
+ If schedules are defined during application initialization then the scheduler will not be started until after the application is started by Tomcat.
43
+
44
+ (The lazy nature of TrinidadScheduler also gives the user time to define a logger outstide of the default configured log4j StdOut logger that
45
+ is included with TrinidadScheduler)
46
+
47
+ Usage
48
+ =========
49
+ The extension defines several methods that return classes based on the configuration options provided. These methods map to the scheduler trigger type
50
+ that Quartz provides. The implemented triggers are CronTrigger, SimpleTrigger, and DateIntervalTrigger.
51
+
52
+ Cron Trigger
53
+ ---------
54
+ To define a process to be run based on a [cron expression](http://en.wikipedia.org/wiki/CRON_expression#CRON_expression)
55
+
56
+ class ScheduledClass < TrinidadScheduler.Cron "0/5 * * * * ?"
57
+ def run
58
+ _logger.info "I am printed every 5 seconds"
59
+ end
60
+ end
61
+
62
+ The method *TrinidadScheduler.Cron* takes a cron expression as it's only argument and returns a class. This anonymous class is the parent of
63
+ ScheduledClass and does the work to wrap ScheduledClass for use as a CronTrigger in Quartz.
64
+
65
+ The instance method "run" must be defined because it is called when the scheduled process is triggered. *_logger* is an instance variable available
66
+ in ScheduledClass which gives the class access to the Quartz logger that is configured.
67
+
68
+ Simple Trigger
69
+ ---------
70
+ Schedule an INFO log message every 5 seconds starting now, setting the end is not necessary in this context, but is done
71
+
72
+ class TestJob < TrinidadScheduler.Simple :start => Time.now, :end => Time.now + 240, :repeat 3, :interval => 5000
73
+ def run
74
+ _logger.info "I am inside this block" #=> prints "I am inside this block" every 5 seconds
75
+ end
76
+ end
77
+
78
+ The Simple Trigger will execute based on options passed to the method *TrinidadScheduler.Simple*, the options available are outlined
79
+ above in the example, none of them are necessary if you only want to trigger the process once. You can define a start and end time as well as how many
80
+ times to fire the trigger along with an interval to be observed between trigger execution.
81
+
82
+ DateInterval Trigger
83
+ ---------
84
+ Schedule an INFO log message every 5 seconds starting now and ending after 4 minutes
85
+
86
+ class TestJob < TrinidadScheduler.DateInterval :start => Time.now, :end => Time.now + 240, :unit => :second, :interval => 5
87
+ def run
88
+ _logger.info "I am inside this block" #=> prints "I am inside this block" every 5 seconds
89
+ end
90
+ end
91
+
92
+ The DateInterval Trigger will execute a triggered process based on the configuration options passed. For more information on using the DateInterval
93
+ trigger consult the source.
94
+
95
+ run_later
96
+ ---------
97
+ Schedules a block of code to run in another Thread after execution proceeds in the current Thread
98
+ *after the job runs it removes itself from the job scheduler
99
+
100
+ Using run_later with default 3 second delay
101
+
102
+ TrinidadScheduler.run_later do
103
+ _logger.info "I am inside this block" #=> prints "I am inside this block"
104
+ end
105
+
106
+ Using run_later with 20 second delay
107
+
108
+ TrinidadScheduler.run_later(:delay => 20) do
109
+ _logger.info "I am inside this block" #=> prints "I am inside this block"
110
+ end
111
+
112
+ Behind the scenes *run_later* is actually implemented using an anonymous class that inherits from TrinidadScheduler.Simple to schedule the run.
113
+
114
+
115
+ Inspiration
116
+ ---------
117
+ Open Source software is a community effort - thanks to all, but the following were instrumental in the inspiration for TrinidadScheduler.
118
+
119
+ [techwhizbang](https://github.com/techwhizbang/jruby-quartz) for handling of Quartz JobFactory
120
+ [why_metaid](https://github.com/evaryont/why_metaid) for metaid extension
121
+ [TERRACOTTA](http://www.terracotta.org/) for continued support Quartz Scheduler
122
+ [calavera](https://github.com/calavera/trinidad) for Trinidad Server
123
+
124
+
125
+ Copyright
126
+ ---------
127
+ Copyright (c) 2011 Brandon Dewitt <brandon+trinidad_scheduler "at" myjibe.com>. See LICENSE for details.
@@ -4,6 +4,8 @@ module Trinidad
4
4
  class SchedulerWebAppExtension < WebAppExtension
5
5
 
6
6
  def configure(tomcat, app_context)
7
+ TrinidadScheduler.trinidad_scheduler_init_log4j
8
+
7
9
  app_context.add_lifecycle_listener(TrinidadScheduler::WebAppListener.new(app_context.servlet_context, @options))
8
10
  end
9
11
  end
@@ -11,6 +13,8 @@ module Trinidad
11
13
  class SchedulerServerExtension < ServerExtension
12
14
 
13
15
  def configure(tomcat)
16
+ TrinidadScheduler.trinidad_scheduler_init_log4j
17
+
14
18
  tomcat.get_host.add_container_listener(TrinidadScheduler::GlobalListener.new(@options))
15
19
  end
16
20
  end
@@ -12,6 +12,10 @@ module TrinidadScheduler
12
12
  TrinidadScheduler.scheduler_exists?(@servlet_context) && !TrinidadScheduler[@servlet_context].is_started
13
13
  end
14
14
 
15
+ def is_started?
16
+ TrinidadScheduler.scheduler_exists?(@servlet_context) && TrinidadScheduler[@servlet_context].is_started
17
+ end
18
+
15
19
  def lifecycle_event(event)
16
20
  case event.type
17
21
  when org.apache.catalina.Lifecycle::START_EVENT then
@@ -21,6 +25,8 @@ module TrinidadScheduler
21
25
  end
22
26
 
23
27
  TrinidadScheduler.set_servlet_started(@servlet_context)
28
+ when org.apache.catalina.Lifecycle::STOP_EVENT then
29
+ TrinidadScheduler[@servlet_context].shutdown if is_started?
24
30
  end
25
31
  end
26
32
  end
@@ -1,6 +1,6 @@
1
1
  module TrinidadScheduler
2
- CONFIG_HOME = File.expand_path(File.dirname(__FILE__) + "/trinidad_scheduler_extension/config")
3
- JAR_HOME = File.expand_path(File.dirname(__FILE__) + "/trinidad_scheduler_extension/jars")
2
+ CONFIG_HOME = File.expand_path(File.dirname(__FILE__) + "/config")
3
+ JAR_HOME = File.expand_path(File.dirname(__FILE__) + "/jars")
4
4
 
5
5
  # Sets log4j properties if not established by Application Servers
6
6
  # TrinidadScheduler is really lazy so this is only set when a scheduler is needed
@@ -1,3 +1,3 @@
1
1
  module TrinidadScheduler
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: trinidad_scheduler_extension
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brandon Dewitt
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-06 00:00:00 -05:00
13
+ date: 2011-06-21 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -32,10 +32,11 @@ extensions: []
32
32
 
33
33
  extra_rdoc_files:
34
34
  - LICENSE
35
- - README
35
+ - README.md
36
+ - README.rdoc
36
37
  files:
37
38
  - LICENSE
38
- - README
39
+ - README.rdoc
39
40
  - lib/trinidad_scheduler_extension.rb
40
41
  - lib/trinidad_scheduler_extension/app_job.rb
41
42
  - lib/trinidad_scheduler_extension/config/log4j.properties
@@ -51,8 +52,9 @@ files:
51
52
  - lib/trinidad_scheduler_extension/scheduler_listener.rb
52
53
  - lib/trinidad_scheduler_extension/trinidad_scheduler.rb
53
54
  - lib/trinidad_scheduler_extension/version.rb
55
+ - README.md
54
56
  has_rdoc: true
55
- homepage: https://github.com/bdewitt/trinidad_scheduler_extension
57
+ homepage: https://github.com/trinidad/trinidad_scheduler_extension
56
58
  licenses: []
57
59
 
58
60
  post_install_message:
@@ -75,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
77
  requirements: []
76
78
 
77
79
  rubyforge_project:
78
- rubygems_version: 1.6.1
80
+ rubygems_version: 1.5.1
79
81
  signing_key:
80
82
  specification_version: 3
81
83
  summary: "Extension to support scheduled jobs in Trinidad: Extension"