Backgroundrb is driving me crazy.
I am trying to schedule a simple job - extremely simple so that I can
understand how it thinks. I have gone through the the
Tutorial/Notes/Examples at:
http://backgroundrb.rubyforge.org/
carefully. Somehow things are not clicking:
Have installed backgrounddb 1.0.4 along with cronic 0.2.3 and packet
0.1.9 gems.
Here is my HelloWorker class in the lib/workers directory of Rails root:
class HelloWorker < BackgrounDRb::MetaWorker
set_worker_name :hello_worker
def create(args = nil)
end
def yml_schedule
puts “yml_schedule - Before”
Post.say_hello
puts “yml_schedule - After”
end
end
Here is my backgroundrb.yml in the config directory;
:backgroundrb:
:port: 11006
:ip: 0.0.0.0
:schedules:
:hello_worker:
:yml_schedule:
:trigger_args: */60 * * * * *
And Here is the Post model from a simple RoR rubyweblog app - this is in
app/models directory and is in post.rb file:
class Post < ActiveRecord::Base
class << self
def say_hello
logger.info ‘Hello from Post model’
end
end
end
As you can see, I am trying to coax backgroundrb to log ‘Hello from Post
model’ every minute and also hoping that “yml schedule - Before” and
“yml schedule after” is going to be printed along with it.
I am getting rather strange output:
- backgroundrb_debug_11006.log file contains the following:
yml_schedule - Before
yml_schedule - After
This is only once and does not repeat.
- The development.log file shows the following:
allow_concurrency=true
Defined connections:
{“ActiveRecord::Base”=>#<ActiveRecord::Base::ConnectionSpecification:0xb7767ea8
@config={:socket=>“/var/run/mysqld/mysqld.sock”, :encoding=>“utf8”,
:password=>nil, :adapter=>“mysql”, :username=>“root”,
:database=>“rubyweblog_dev”}, @adapter_method=“mysql_connection”>}
Active connections: {}
Active connection name: ActiveRecord::Base
SQL (0.000219) SET NAMES ‘utf8’
SQL (0.000124) SET SQL_AUTO_IS_NULL=0
SQL (0.000083) BEGIN
BdrbJobQueue Load (0.000660) SELECT * FROM bdrb_job_queues
WHERE
(bdrb_job_queues
.taken
= 0 AND bdrb_job_queues
.worker_name
=
‘hello_worker’) LIMIT 1 FOR UPDATE
SQL (0.000119) COMMIT
SQL (0.000224) BEGIN
BdrbJobQueue Load (0.000802) SELECT * FROM bdrb_job_queues
WHERE
(bdrb_job_queues
.taken
= 0 AND bdrb_job_queues
.worker_name
=
‘hello_worker’) LIMIT 1 FOR UPDATE
SQL (0.000176) COMMIT
Hello from Post model
SQL (0.000188) BEGIN
BdrbJobQueue Load (0.000571) SELECT * FROM bdrb_job_queues
WHERE
(bdrb_job_queues
.taken
= 0 AND bdrb_job_queues
.worker_name
=
‘hello_worker’) LIMIT 1 FOR UPDATE
SQL (0.000114) COMMIT
SQL (0.000203) BEGIN
BdrbJobQueue Load (0.000639) SELECT * FROM bdrb_job_queues
WHERE
(bdrb_job_queues
.taken
= 0 AND bdrb_job_queues
.worker_name
=
‘hello_worker’) LIMIT 1 FOR UPDATE
SQL (0.000106) COMMIT
SQL (0.000204) BEGIN
BdrbJobQueue Load (0.000593) SELECT * FROM bdrb_job_queues
WHERE
(bdrb_job_queues
.taken
= 0 AND bdrb_job_queues
.worker_name
=
‘hello_worker’) LIMIT 1 FOR UPDATE
SQL (0.000104) COMMIT
SQL (0.000200) BEGIN
BdrbJobQueue Load (0.000610) SELECT * FROM bdrb_job_queues
WHERE
(bdrb_job_queues
.taken
= 0 AND bdrb_job_queues
.worker_name
=
‘hello_worker’) LIMIT 1 FOR UPDATE
SQL (0.000103) COMMIT
SQL (0.000206) BEGIN
BdrbJobQueue Load (0.000594) SELECT * FROM bdrb_job_queues
WHERE
(bdrb_job_queues
.taken
= 0 AND bdrb_job_queues
.worker_name
=
‘hello_worker’) LIMIT 1 FOR UPDATE
SQL (0.000105) COMMIT
As you can see this also contains ‘Hello from Post model’ ONCE. And the
whole BdrdJobQueue Load keeps repeating every minute, but will not print
the output message. I am not sure why the class method say_hello is not
called from within the hello_worker every minute?
Please help.
Thanks.
Bharat