. // example of a web interface to remote job submission // // Notes: // - You'll need to adapt/extend this considerably, // especially if you want to run this // on a server other than the BOINC project serve. // - For convenience, this uses some functions from BOINC // (page_head() etc.). // When you adapt this to your own purposes, // you can strip out this stuff if the web site doesn't use BOINC require_once("../inc/submit.inc"); require_once("../inc/submit_db.inc"); require_once("../inc/util.inc"); require_once("../project/project.inc"); error_reporting(E_ALL); ini_set('display_errors', true); ini_set('display_startup_errors', true); $project = $master_url; // from project.inc $user = get_logged_in_user(); $auth = $user->authenticator; // the job submission "home page": // show the user's in-progress and completed batches, // and a button for creating a new batch // function handle_main() { global $project, $auth; $req->project = $project; $req->authenticator = $auth; list($batches, $errmsg) = boinc_query_batches($req); if ($errmsg) error_page($errmsg); page_head("Job submission and control"); show_button("submit_example.php?action=create_form", "Create new batch"); $first = true; foreach ($batches as $batch) { if ($batch->state != BATCH_STATE_IN_PROGRESS) continue; if ($first) { $first = false; echo "
You have no in-progress batches.\n"; } else { end_table(); } $first = true; foreach ($batches as $batch) { if ($batch->state != BATCH_STATE_COMPLETE) continue; if ($first) { $first = false; echo "
You have no completed batches.\n"; } else { end_table(); } $first = true; foreach ($batches as $batch) { if ($batch->state != BATCH_STATE_ABORTED) continue; if ($first) { $first = false; echo "
Return to job control page
";
page_tail();
}
}
// show the details of an existing batch
//
function handle_query_batch() {
global $project, $auth;
$req->project = $project;
$req->authenticator = $auth;
$req->batch_id = get_int('batch_id');
list($batch, $errmsg) = boinc_query_batch($req);
if ($errmsg) error_page($errmsg);
page_head("Batch $req->batch_id");
start_table();
row2("name", $batch->name);
row2("application", $batch->app_name);
row2("state", batch_state_string($batch->state));
row2("# jobs", $batch->njobs);
row2("# error jobs", $batch->nerror_jobs);
row2("progress", sprintf("%.0f%%", $batch->fraction_done*100));
if ($batch->completion_time) {
row2("completed", local_time_str($batch->completion_time));
}
row2("Credit, estimated", $batch->credit_estimate);
row2("Credit, canonical instances", $batch->credit_canonical);
row2("Credit, total", $batch->credit_total);
end_table();
$url = boinc_get_output_files($req);
show_button($url, "Get zipped output files");
switch ($batch->state) {
case BATCH_STATE_IN_PROGRESS:
echo "
";
show_button(
"submit_example.php?action=abort_batch_confirm&batch_id=$req->batch_id",
"Abort batch"
);
break;
case BATCH_STATE_COMPLETE:
case BATCH_STATE_ABORTED:
echo "
";
show_button(
"submit_example.php?action=retire_batch_confirm&batch_id=$req->batch_id",
"Retire batch"
);
break;
}
echo "
"; show_button( "submit_example.php?action=abort_batch&batch_id=$batch_id", "Yes - abort batch" ); page_tail(); } function handle_abort_batch() { global $project, $auth; $req->project = $project; $req->authenticator = $auth; $req->batch_id = get_int('batch_id'); $errmsg = boinc_abort_batch($req); if ($errmsg) error_page($errmsg); page_head("Batch aborted"); echo " Return to job control page. "; page_tail(); } function handle_retire_batch_confirm() { $batch_id = get_int('batch_id'); page_head("Confirm retire batch"); echo " Retiring a batch will remove all of its output files. Are you sure you want to do this?
"; show_button( "submit_example.php?action=retire_batch&batch_id=$batch_id", "Yes - retire batch" ); page_tail(); } function handle_retire_batch() { global $project, $auth; $req->project = $project; $req->authenticator = $auth; $req->batch_id = get_int('batch_id'); $errmsg = boinc_retire_batch($req); if ($errmsg) error_page($errmsg); page_head("Batch retired"); echo " Return to job control page. "; page_tail(); } $action = get_str('action', true); switch ($action) { case '': handle_main(); break; case 'create_form': handle_create_form(); break; case 'create_action': handle_create_action(); break; case 'query_batch': handle_query_batch(); break; case 'query_job': handle_query_job(); break; case 'abort_batch_confirm': handle_abort_batch_confirm(); break; case 'abort_batch': handle_abort_batch(); break; case 'retire_batch_confirm': handle_retire_batch_confirm(); break; case 'retire_batch': handle_retire_batch(); break; default: error_page('no such action'); } ?>