| 35 | == A script to generate jobs == |
| 36 | |
| 37 | We'll need a program to generate jobs. |
| 38 | This is done with a PHP script: |
| 39 | [source:/trunk/html/ops/bossa_test.php html/ops/bossa_test.php]. |
| 40 | |
| 41 | The first part of this script is code for generating an image; |
| 42 | the key functions are '''make_test_case()''', |
| 43 | which generates a structure saying if and where there's an ellipse, |
| 44 | and '''make_image()''', which generates an image given this info. |
| 45 | |
| 46 | Next we have |
| 47 | {{{ |
| 48 | function make_job($app, $batch, $i, $config) { |
| 49 | // create the image file; |
| 50 | // store it in the download directory hierarchy |
| 51 | // |
| 52 | $jobname = "job_$batch_$i"; |
| 53 | $case = make_test_case(); |
| 54 | $filename = "$jobname.png"; |
| 55 | $path = dir_hier_path( |
| 56 | $filename, $config->download_dir, $config->uldl_dir_fanout |
| 57 | ); |
| 58 | $url = dir_hier_url( |
| 59 | $filename, $config->download_url, $config->uldl_dir_fanout |
| 60 | ); |
| 61 | imagepng(make_image($case), $path); |
| 62 | $case->url = $url; |
| 63 | |
| 64 | // make a job record in the Bossa database |
| 65 | // |
| 66 | $job = new BossaJob; |
| 67 | $job->app_id = $app->id; |
| 68 | $job->batch = $batch; |
| 69 | $job->time_estimate = 30; |
| 70 | $job->time_limit = 600; |
| 71 | $job->name = $jobname; |
| 72 | $job->info = json_encode($case); |
| 73 | |
| 74 | if (!$job->insert()) { |
| 75 | echo "BossaJob::insert failed: ", mysql_error(), "\n"; |
| 76 | exit(1); |
| 77 | } |
| 78 | } |
| 79 | }}} |
| 80 | |
| 81 | This creates one job. |
| 82 | It does the following: |
| 83 | |
| 84 | * Choose a name for the job, and a name for the corresponding image file. |
| 85 | * Decide where the file will go in the project's download hierarchy. |
| 86 | * Create the image file. |
| 87 | * Create a job record in the Bossa database. |
| 88 | |
| 89 | Finally we have: |
| 90 | {{{ |
| 91 | function make_jobs() { |
| 92 | $c = get_config(); |
| 93 | $config = null; |
| 94 | $config->download_dir = parse_config($c, "<download_dir>"); |
| 95 | $config->download_url = parse_config($c, "<download_url>"); |
| 96 | $config->uldl_dir_fanout = parse_config($c, "<uldl_dir_fanout>"); |
| 97 | $app = BossaApp::lookup_name("bossa_test"); |
| 98 | if (!$app) { |
| 99 | echo "Application $appname not found\n"; |
| 100 | exit(1); |
| 101 | } |
| 102 | $batch = time(); |
| 103 | for ($i=0; $i<10; $i++) { |
| 104 | make_job($app, $batch, $i, $config); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | if ($_GET['make_jobs']) { |
| 109 | make_jobs(); |
| 110 | } else { |
| 111 | header ("Content-type: image/png"); |
| 112 | imagepng(make_image(make_test_case())); |
| 113 | } |
| 114 | }}} |
| 115 | |
| 116 | '''make_jobs()''' parses the project configuration file, |
| 117 | looks up the application in the database, and creates 10 jobs. |
| 118 | You can invoke this by visiting |
| 119 | '''http://a.b.c/test_ops/bossa_test.php?make_jobs'''. |
| 120 | |
| 121 | |
| 122 | |