- Initial checkin of Bossa code.

This isn't part of BOINC and eventually
    it should go in a different repository,
    but for now I'm putting it here.

svn path=/trunk/boinc/; revision=13851
This commit is contained in:
David Anderson 2007-10-16 17:12:48 +00:00
parent 00dbc6db34
commit ad2fe67886
5 changed files with 179 additions and 0 deletions

View File

@ -9520,3 +9520,17 @@ Bruce 15 Oct 2007
inc/
db_ops.inc
David 16 Oct 2007
- Initial checkin of Bossa code.
This isn't part of BOINC and eventually
it should go in a different repository,
but for now I'm putting it here.
html/
inc/
bossa_db.inc
ops/
bossa_make_jobs_example.php
bossa_setup_example.php
user/
bossa_get_job.php

83
html/inc/bossa_db.inc Normal file
View File

@ -0,0 +1,83 @@
<?php
class Bossa {
function insert_app(&$app) {
if (!$app->long_jobs) $app->long_jobs = 0;
$now = time();
$query = "insert into bossa_app (create_time, name, user_friendly_name, long_jobs, start_url, finish_url) values ($now, '$app->name', '$app->user_friendly_name', $app->long_jobs, '$app->start_url', '$app->finish_url')";
echo $query;
$result = mysql_query($query);
if (!$result) return false;
$app->id = mysql_insert_id();
return true;
}
function app_lookup_name($name) {
$result = mysql_query("select * from bossa_app where name='$name'");
if (!$result) return null;
$app = mysql_fetch_object($result);
mysql_free_result($result);
return $app;
}
function app_lookup_id($id) {
$result = mysql_query("select * from bossa_app where id='$id'");
if (!$result) return null;
$app = mysql_fetch_object($result);
mysql_free_result($result);
return $app;
}
function insert_job(&$job) {
$now = time();
$query = "insert into bossa_job (create_time, name, app_id, info, batch, time_estimate, time_limit, more_needed, npending, nsuccess, nsuccess_needed) values ($now, '$job->name', $job->app_id, '$job->info', $job->batch, $job->time_estimate, $job->time_limit, 1, 0, 0, $job->nsuccess_needed)";
$result = mysql_query($query);
if (!$result) {
echo "$query\n";
return false;
}
$job->id = mysql_insert_id();
return true;
}
function insert_job_inst(&$ji) {
$now = time();
$query = "insert into bossa_job_inst (create_time, job_id, user_id) values ($now, $ji->job_id, $ji->user_id)";
$result = mysql_query($query);
if (!$result) {
echo "$query\n";
return false;
}
$ji->id = mysql_insert_id();
return true;
}
// Assign a job from the given app to the given user.
// Returns the job instance or NULL.
//
function assign_job($app, $user) {
// this query skips jobs for which this user
// has already been assigned an instance
//
$query = "select bossa_job.* from bossa_job left join bossa_job_inst on bossa_job_inst.job_id = bossa_job.id where bossa_job.more_needed<>0 and bossa_job_inst.user_id is null limit 1";
echo "$query\n";
$result = mysql_query($query);
if (!$result) return null;
$job = mysql_fetch_object($result);
mysql_free_result($result);
echo "<hr>";
print_r($job);
echo "<hr>";
$ji->user_id = $user->id;
$ji->job_id = $job->id;
if (!Bossa::insert_job_inst($ji)) {
echo mysql_error();
return null;
}
return $ji;
}
}
?>

View File

@ -0,0 +1,31 @@
<?php
require_once("../bossa_inc/bossa_db.inc");
require_once("../inc/db.inc");
db_init();
function make_jobs() {
$app = Bossa::app_lookup_name('bossa_test');
if (!$app) {
echo "No app\n";
exit(1);
}
$job->app_id = $app->id;
$job->batch = 0;
$job->time_estimate = 30;
$job->time_limit = 600;
$job->nsuccess_needed = 3;
for ($i=0; $i<10; $i++) {
$job->name = "job_$i";
$job->job_info = "$i";
if (!Bossa::insert_job($job)) {
echo "failed: ", mysql_error();
exit(1);
}
}
}
make_jobs();
?>

View File

@ -0,0 +1,21 @@
<?php
require_once("../bossa_inc/bossa_db.inc");
require_once("../inc/db.inc");
db_init();
// Set up Bossa applications.
// Customize and rename this file.
$ba->name = 'bossa_test';
$ba->user_friendly_name = 'Simple pattern recognition';
$ba->start_url = 'test_start.php';
if (Bossa::insert_app($ba)) {
echo "success\n";
} else {
echo "failed ", mysql_error();
}
?>

View File

@ -0,0 +1,30 @@
<?php
require_once("../inc/util.inc");
require_once("../inc/db.inc");
require_once("../bossa_inc/bossa_db.inc");
db_init();
$user = get_logged_in_user();
$bossa_app_id = get_int('bossa_app_id');
$app = Bossa::app_lookup_id($bossa_app_id);
if (!$app) {
error_page("no such app: $bossa_app_id");
}
$ji = Bossa::assign_job($app, $user);
if ($ji) {
$url = $app->start_url."&job_info=".$job->job_info;
Header("Location: $url");
} else {
page_head("No jobs available");
echo "
Sorry, no jobs are available right not.
Please try again later.
";
page_tail();
}
?>