JSON-encode stuff
    use text instead of varchar(255) a couple of places
    create Bossa class for utility functions

svn path=/trunk/boinc/; revision=13908
This commit is contained in:
David Anderson 2007-10-18 21:43:25 +00:00
parent 0b98b0f0cd
commit 094eb0095e
8 changed files with 87 additions and 36 deletions

View File

@ -9645,3 +9645,20 @@ Rom 18 Oct 2007
clientlib/win/
IdleTracker.cpp
David 18 Oct 2007
- Bossa:
JSON-encode stuff
use text instead of varchar(255) a couple of places
create Bossa class for utility functions
db/
bossa_constraints.sql
bossa_schema.sql
html/
inc/
bossa.inc (new)
ops/
bossa_make_jobs_example.php
user/
bossa_example.php

View File

@ -3,7 +3,7 @@ alter table bossa_app
alter table bossa_job
add unique(name),
add index bj_more_needed(app, more_needed);
add index bj_more_needed(app_id, more_needed);
alter table bossa_job_inst
add index bji_job(job_id),

View File

@ -6,7 +6,7 @@ create table bossa_app (
long_jobs tinyint not null,
start_url varchar(255) not null,
deprecated tinyint not null,
beta tinyint not null,
info text,
primary key(id)
);
@ -15,7 +15,7 @@ create table bossa_job (
create_time integer not null,
name varchar(255) not null,
app_id integer not null,
info varchar(255) not null,
info text,
batch integer not null,
time_estimate integer not null,
time_limit integer not null,
@ -32,6 +32,12 @@ create table bossa_job_inst (
job_id integer not null,
user_id integer not null,
finish_time integer not null,
info varchar(255) not null,
info text,
primary key(id)
);
create table bossa_app_user (
app_id integer not null,
user_id integer not null,
info text
);

View File

@ -2,6 +2,16 @@
$project_news = array(
array("October 17, 2007",
"Congratulations to the <a href=http://www.ukboincteam.org.uk/>UK BOINC Team</a>,
which today became the first UK-specific team to
pass the 100 million combined credits mark."
),
array("October 17, 2007",
"An article in Nature,
<a href=http://www.nature.com/news/2007/071016/full/449765a.html>The shape of protein structures to come</a>, discusses the goals and progress of the
<a href= http://boinc.bakerlab.org/rosetta/>Rosetta@home</a> project from the University of Washington."
),
array("October 12, 2007",
"LHC@home has moved from CERN to the University of London.
Read about it <a href=http://www.interactions.org/cms/?pid=1025457>here</a>."

30
html/inc/bossa.inc Normal file
View File

@ -0,0 +1,30 @@
<?php
require_once("../inc/util.inc");
require_once("../inc/bossa_db.inc");
class Bossa {
static function script_init(&$user, &$bj, &$bji) {
db_init();
$user = get_logged_in_user();
$bji = BossaJobInst::lookup_id(get_int('bji'));
if (!$bji) {
error_page("No such job instance");
}
if ($bji->user_id != $user->id) {
error_page("Bad user ID");
}
$bj = BossaJob::lookup_id($bji->job_id);
if (!$bj) {
error_page("No such job");
}
}
static function show_next_job($bj) {
$url = "bossa_get_job.php?bossa_app_id=$bj->app_id";
Header("Location: $url");
}
}
?>

View File

@ -1,9 +1,9 @@
<?php
function bossa_lookup($id, $table) {
function bossa_lookup($id, $table, $classname) {
$result = mysql_query("select * from $table where id='$id'");
if (!$result) return null;
$obj = mysql_fetch_object($result);
$obj = mysql_fetch_object($result, $classname);
mysql_free_result($result);
return $obj;
}
@ -22,13 +22,13 @@ class BossaApp {
static function lookup_name($name) {
$result = mysql_query("select * from bossa_app where name='$name'");
if (!$result) return null;
$app = mysql_fetch_object($result);
$app = mysql_fetch_object($result, 'BossaApp');
mysql_free_result($result);
return $app;
}
static function lookup_id($id) {
return bossa_lookup($id, 'bossa_app');
return bossa_lookup($id, 'bossa_app', 'BossaApp');
}
}
@ -48,7 +48,7 @@ class BossaJob {
return mysql_query("update bossa_job set $clause where id=$this->id");
}
static function lookup_id($id) {
return bossa_lookup($id, 'bossa_job');
return bossa_lookup($id, 'bossa_job', 'BossaJob');
}
}
@ -66,7 +66,7 @@ class BossaJobInst {
}
static function lookup_id($id) {
return bossa_lookup($id, 'bossa_job_inst');
return bossa_lookup($id, 'bossa_job_inst', 'BossaJobInst');
}
function update($clause) {
@ -81,10 +81,10 @@ class BossaJobInst {
// 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);
$job = mysql_fetch_object($result, 'BossaJob');
if (!$job) return null;
mysql_free_result($result);
echo "<hr>";

View File

@ -19,9 +19,10 @@ function make_jobs() {
$job->time_limit = 600;
$job->nsuccess_needed = 3;
for ($i=0; $i<10; $i++) {
$j = $i % 2;
$job->name = "job_$i";
$job->info = "$j";
$info = null;
$info->number = $i % 2;
$job->info = json_encode($info);
if (!$job->insert()) {
echo "BossaJob::insert failed: ", mysql_error(), "\n";
exit(1);

View File

@ -1,9 +1,8 @@
<?php
require_once("../inc/util.inc");
require_once("../inc/bossa_db.inc");
require_once("../inc/bossa.inc");
db_init();
echo "foo";
// Bossa example.
// Show the user an image and ask them whether it's a zero or one.
@ -12,8 +11,8 @@ function show_job($bj, $bji) {
if ($bji->finish_time) {
error_page("You already finished this job");
}
$i = $bj->info;
$img_url = "http://boinc.berkeley.edu/images/number_$i.jpg";
$info = json_decode($bj->info);
$img_url = "http://boinc.berkeley.edu/images/number_".$info->number.".jpg";
echo "
<form method=get action=bossa_example.php>
<input type=hidden name=bji value=$bji->id>
@ -29,29 +28,17 @@ function show_job($bj, $bji) {
}
function handle_job_completion($bj, $bji) {
$response = get_int('response');
print_r($bji);
$bji->info = "response=$response";
$response = null;
$response->number = get_int('response');
$bji->info = json_encode($response);
$bji->completed($bj);
// show another job immediately
//
$url = "bossa_get_job.php?bossa_app_id=$bj->app_id";
Header("Location: $url");
Bossa::show_next_job($bj);
}
$user = get_logged_in_user();
$bji = BossaJobInst::lookup_id(get_int('bji'));
if (!$bji) {
error_page("No such job instance");
}
if ($bji->user_id != $user->id) {
error_page("Bad user ID");
}
$bj = BossaJob::lookup_id($bji->job_id);
if (!$bj) {
error_page("No such job");
}
Bossa::script_init($user, $bj, $bji);
if ($_GET['submit']) {
handle_job_completion($bj, $bji);