From 094eb0095ef51d3a4a12290e2cf1afb2e37fbd51 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 18 Oct 2007 21:43:25 +0000 Subject: [PATCH] - Bossa: 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 --- checkin_notes | 17 +++++++++++++++ db/bossa_constraints.sql | 2 +- db/bossa_schema.sql | 12 ++++++++--- doc/boinc_news.php | 10 +++++++++ html/inc/bossa.inc | 30 +++++++++++++++++++++++++++ html/inc/bossa_db.inc | 16 +++++++------- html/ops/bossa_make_jobs_example.php | 5 +++-- html/user/bossa_example.php | 31 ++++++++-------------------- 8 files changed, 87 insertions(+), 36 deletions(-) create mode 100644 html/inc/bossa.inc diff --git a/checkin_notes b/checkin_notes index e75b395085..bd8f154e76 100644 --- a/checkin_notes +++ b/checkin_notes @@ -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 diff --git a/db/bossa_constraints.sql b/db/bossa_constraints.sql index 94530740ce..fa73f16e4d 100644 --- a/db/bossa_constraints.sql +++ b/db/bossa_constraints.sql @@ -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), diff --git a/db/bossa_schema.sql b/db/bossa_schema.sql index 8c7faf42d1..8dcbf4200b 100644 --- a/db/bossa_schema.sql +++ b/db/bossa_schema.sql @@ -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 +); diff --git a/doc/boinc_news.php b/doc/boinc_news.php index 214b4166b4..7c9403bc12 100644 --- a/doc/boinc_news.php +++ b/doc/boinc_news.php @@ -2,6 +2,16 @@ $project_news = array( +array("October 17, 2007", + "Congratulations to the UK BOINC Team, + which today became the first UK-specific team to + pass the 100 million combined credits mark." +), +array("October 17, 2007", + "An article in Nature, + The shape of protein structures to come, discusses the goals and progress of the + Rosetta@home project from the University of Washington." +), array("October 12, 2007", "LHC@home has moved from CERN to the University of London. Read about it here." diff --git a/html/inc/bossa.inc b/html/inc/bossa.inc new file mode 100644 index 0000000000..2093ed4efb --- /dev/null +++ b/html/inc/bossa.inc @@ -0,0 +1,30 @@ +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"); + } +} + +?> diff --git a/html/inc/bossa_db.inc b/html/inc/bossa_db.inc index a5e483c1ab..efe720ca19 100644 --- a/html/inc/bossa_db.inc +++ b/html/inc/bossa_db.inc @@ -1,9 +1,9 @@ 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 "
"; diff --git a/html/ops/bossa_make_jobs_example.php b/html/ops/bossa_make_jobs_example.php index 0984c07736..5bc98534cc 100644 --- a/html/ops/bossa_make_jobs_example.php +++ b/html/ops/bossa_make_jobs_example.php @@ -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); diff --git a/html/user/bossa_example.php b/html/user/bossa_example.php index d5ad879fc6..baed39a4cc 100644 --- a/html/user/bossa_example.php +++ b/html/user/bossa_example.php @@ -1,9 +1,8 @@ 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 "
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);