|
Revision 164, 1.2 kB
(checked in by miyagawa, 7 months ago)
|
|
PostgreSQL patch from clkao
|
| Line | |
|---|
| 1 | # $Id$ |
|---|
| 2 | # -*-perl-*- |
|---|
| 3 | |
|---|
| 4 | use strict; |
|---|
| 5 | use warnings; |
|---|
| 6 | |
|---|
| 7 | require 't/lib/db-common.pl'; |
|---|
| 8 | |
|---|
| 9 | use TheSchwartz; |
|---|
| 10 | use Test::More tests => 6; |
|---|
| 11 | |
|---|
| 12 | run_tests(2, sub { |
|---|
| 13 | setup_dbs('ts1'); |
|---|
| 14 | teardown_dbs('ts2'); # doesn't exist |
|---|
| 15 | |
|---|
| 16 | my $client = test_client(dbs => ['ts2', 'ts1'], |
|---|
| 17 | init => 0); |
|---|
| 18 | |
|---|
| 19 | # insert a job |
|---|
| 20 | my $n_handles = 0; |
|---|
| 21 | for (1..50) { |
|---|
| 22 | my $handle = $client->insert("Worker::Addition", { numbers => [1, 2] }); |
|---|
| 23 | $n_handles++ if $handle; |
|---|
| 24 | } |
|---|
| 25 | is($n_handles, 50, "got 50 handles"); |
|---|
| 26 | |
|---|
| 27 | # let's do some work. the tedious way, specifying which class should grab a job |
|---|
| 28 | my $n_grabbed = 0; |
|---|
| 29 | while (my $job = Worker::Addition->grab_job($client)) { |
|---|
| 30 | $n_grabbed++; |
|---|
| 31 | } |
|---|
| 32 | is($n_grabbed, 50, "grabbed 50 times"); |
|---|
| 33 | |
|---|
| 34 | teardown_dbs('ts1'); |
|---|
| 35 | }); |
|---|
| 36 | |
|---|
| 37 | ############################################################################ |
|---|
| 38 | package Worker::Addition; |
|---|
| 39 | use base 'TheSchwartz::Worker'; |
|---|
| 40 | |
|---|
| 41 | sub work { |
|---|
| 42 | my ($class, $job) = @_; |
|---|
| 43 | |
|---|
| 44 | # .... |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | # tell framework to set 'grabbed_until' to time() + 60. because if |
|---|
| 48 | # we can't add some numbers in 30 seconds, our process probably |
|---|
| 49 | # failed and work should be reassigned. |
|---|
| 50 | sub grab_for { 30 } |
|---|
| 51 | |
|---|