Pivotal Knowledge Base

Follow

Is it possible to run scheduled tasks on PWS?

Purpose

PWS currently has no support for scheduled tasks, but it is possible to implement the feature in your application. Here is an example in Ruby language.

Instructions

There are Ruby language scheduling libraries to choose from. For this example, we are going to use clockwork.

At first, add the clockwork gem to Gemfile, it will look like

source 'https://rubygems.org'
gem 'clockwork'

Run 'bundle install' to generate Gemfile.lock.

Second, created Ruby script scheduler.rb, and paste following code into the script file. You can create your task and replace # line with the task. 

module Clockwork
every 1.minute, '1 minute interval task' do
# ScheduledTaskOneMinute.run
end every 4.minutes, '4 minutes interval task' do
# ScheduledTaskFourMinute.run
end every 1.hour, '1 hour interval task' do
# ScheduledTaskOneHour.run
end every 1.day, '1 day interval task ', at: '00:00' do
# ScheduledTaskOneDay.run
end
end

Finally, deploy the app to PWS by running "cf push scheduler -n <hostname> -c 'clockwork scheduler.rb' --no-route". You should see output to the following in "cf logs scheduler":

2015-06-30T13:48:33.13+0900 [App/0] OUT I, [2015-06-30T04:48:33.131656 #29] INFO -- : Starting clock for 4 events: [ 1 minute interval task 4 minutes interval task 1 hour interval task 1 day interval task ]
2015-06-30T13:48:33.13+0900 [App/0] OUT I, [2015-06-30T04:48:33.131783 #29] INFO -- : Triggering '1 minute interval task'
2015-06-30T13:48:33.13+0900 [App/0] OUT I, [2015-06-30T04:48:33.131825 #29] INFO -- : Triggering '4 minutes interval task'
2015-06-30T13:48:33.13+0900 [App/0] OUT I, [2015-06-30T04:48:33.131861 #29] INFO -- : Triggering '1 hour interval task'
2015-06-30T13:49:33.00+0900 [App/0] OUT I, [2015-06-30T04:49:33.002244 #29] INFO -- : Triggering '1 minute interval task'
2015-06-30T13:50:33.00+0900 [App/0] OUT I, [2015-06-30T04:50:33.001262 #29] INFO -- : Triggering '1 minute interval task'

Additional Information

There is a service provider Temporize available in PWS marketplace, it provides more simple and flexible job scheduling for your application.

Comments

Powered by Zendesk