function do_post_testbasicphp_thing_v1($job, $resp) { $resp->status()->progress(10); $resp->status()->add_message("processing"); # test SWIG wapper for scoreboarding Scoreboard::initialize($resp->status()->component()); $sb = Scoreboard::get_scoreboard(); $sb->increment_counter("status", "testbasicphp"); $sw = new StopWatch(); $sw->start(); $sw->stop(); $sb->update_duration_hours("status", "testbasicphp", "duration_success", $sw); if ($job->operation() == "create") { // post-create where the resource id is created for user // (instead of a PUT where the user specifies the name) // get the generated id $in = json_decode($job->content(), true); $in["id"] = $job->resource_name(); file_put_contents(DBDIR . $job->resource_name(), json_encode($in)); } else { $args = $job->arguments(); // post update if (file_exists(DBDIR . $args[0])) { $in = json_decode($job->content(), true); $out = json_decode(file_get_contents(DBDIR . $args[0]), true); $out["stuff"] = $in["stuff"]; file_put_contents(DBDIR . $args[0], json_encode($out)); } else { throw new ERR_NOT_FOUND("thing \"" . $args[0] . "\" not found"); } } $resp->status()->add_message("done"); return Worker::WORKER_SUCCESS; }