Class: TorqueBox::ScheduledJob
- Inherits:
-
Object
- Object
- TorqueBox::ScheduledJob
- Defined in:
- lib/torquebox/scheduled_job.rb
Overview
This class is a Ruby API to manipulating TorqueBox scheduled jobs.
Class Method Summary collapse
-
.at(class_name, options = {}) ⇒ java.util.concurrent.CountDownLatch
Creates new ‘at’ job.
-
.at_sync(class_name, options = {}) ⇒ Boolean
Creates new ‘at’ job.
-
.list ⇒ Array<org.torquebox.jobs.ScheduledJob>
List all scheduled jobs of this application.
-
.lookup(name) ⇒ org.torquebox.jobs.ScheduledJob
Lookup a scheduled job of this application by name.
-
.remove(name) ⇒ java.util.concurrent.CountDownLatch
Removes a scheduled job.
-
.remove_sync(name) ⇒ Boolean
Removes a scheduled job.
-
.schedule(class_name, cron, options = {}) ⇒ java.util.concurrent.CountDownLatch
Creates a new scheduled job.
-
.schedule_sync(class_name, cron, options = {}) ⇒ Boolean
Creates a new scheduled job.
Class Method Details
.at(class_name, options = {}) ⇒ java.util.concurrent.CountDownLatch
This is an asynchronous method.
Creates new ‘at’ job.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/torquebox/scheduled_job.rb', line 107 def at(class_name, = {}) raise "No job class name provided" if class_name.nil? raise "Invalid options for scheduling the job" if .nil? or !.is_a?(Hash) raise "Invalid type for :in, should be a Fixnum" if ![:in].nil? and ![:in].is_a?(Fixnum) raise "You can't specify both :at and :in" if .has_key?(:at) and .has_key?(:in) raise "You can't specify :repeat without :every" if .has_key?(:repeat) and !.has_key?(:every) raise "You can't specify :until without :every" if .has_key?(:until) and !.has_key?(:every) = { :singleton => false, :name => class_name, :timeout => "0s", :repeat => 0, :every => 0, :at => Time.now, :async => true }.merge() if .has_key?(:in) start = Time.now + [:in] / 1000.0 else start = [:at] end with_schedulizer do |schedulizer| schedulizer.create_at_job(class_name.to_s, start, [:until], [:every], [:repeat], [:timeout], [:name], [:description], [:config], [:singleton]) end end |
.at_sync(class_name, options = {}) ⇒ Boolean
This is a synchronous method.
This method accepts the same parameters as available in the at method.
Creates new ‘at’ job.
142 143 144 145 |
# File 'lib/torquebox/scheduled_job.rb', line 142 def at_sync(class_name, = {}) latch = at(class_name, ) wait_for_latch(latch) end |
.list ⇒ Array<org.torquebox.jobs.ScheduledJob>
List all scheduled jobs of this application.
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/torquebox/scheduled_job.rb', line 180 def list prefix = job_service_name.canonical_name service_names = TorqueBox::MSC.service_names.select do |service_name| name = service_name.canonical_name name.start_with?(prefix) && !name.end_with?('mbean') end service_names.map do |service_name| service = TorqueBox::MSC.get_service(service_name) service.nil? ? nil : service.value end.select { |v| !v.nil? } end |
.lookup(name) ⇒ org.torquebox.jobs.ScheduledJob
The ScheduledJob instances returned by this and the list methods are not instances of this class but are instead Java objects of type org.torquebox.jobs.ScheduledJob. There are more methods available on these instances than what’s shown in the example here, but only the methods shown are part of our documented API.
Lookup a scheduled job of this application by name.
214 215 216 217 218 |
# File 'lib/torquebox/scheduled_job.rb', line 214 def lookup(name) service_name = job_service_name.append(name) service = TorqueBox::MSC.get_service(service_name) service.nil? ? nil : service.value end |
.remove(name) ⇒ java.util.concurrent.CountDownLatch
Removes a scheduled job.
This method removes the job asynchronously.
154 155 156 157 158 159 160 161 |
# File 'lib/torquebox/scheduled_job.rb', line 154 def remove(name) raise "No job name provided" if name.nil? raise "Couldn't find a job with name '#{name}''" if TorqueBox::ScheduledJob.lookup(name).nil? with_schedulizer do |schedulizer| schedulizer.remove_job(name) end end |
.remove_sync(name) ⇒ Boolean
This is a synchronous method.
This method accepts the same parameters as available in the remove method.
Removes a scheduled job.
169 170 171 172 |
# File 'lib/torquebox/scheduled_job.rb', line 169 def remove_sync(name) latch = remove(name) wait_for_latch(latch) end |
.schedule(class_name, cron, options = {}) ⇒ java.util.concurrent.CountDownLatch
This is an asynchronous method.
Creates a new scheduled job.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/torquebox/scheduled_job.rb', line 51 def schedule(class_name, cron, = {}) raise "No job class name provided" if class_name.nil? raise "No cron expression provided" if cron.nil? = { :name => class_name.to_s, :singleton => true, :stopped => false, :timeout => "0s" }.merge() with_schedulizer do |schedulizer| schedulizer.create_job(class_name.to_s, cron, [:timeout], [:name], [:description], [:config], [:singleton], [:stopped]) end end |
.schedule_sync(class_name, cron, options = {}) ⇒ Boolean
This is a synchronous method.
This method accepts the same parameters as available in the schedule method.
Creates a new scheduled job.
73 74 75 76 |
# File 'lib/torquebox/scheduled_job.rb', line 73 def schedule_sync(class_name, cron, = {}) latch = schedule(class_name, cron, ) wait_for_latch(latch) end |