/** * At this point, the output has been sent to the browser, so we can take some time * to run a schedule task. */ static function gallery_shutdown() { try { $schedule = ORM::factory("schedule")->where("next_run_datetime", "<=", time())->where("busy", "!=", 1)->order_by("next_run_datetime")->find_all(1); if ($schedule->count()) { $schedule = $schedule->current(); $schedule->busy = true; $schedule->save(); try { if (empty($schedule->task_id)) { $task = task::start($schedule->task_callback); $schedule->task_id = $task->id; } $task = task::run($schedule->task_id); if ($task->done) { $schedule->next_run_datetime += $schedule->interval; $schedule->task_id = null; } $schedule->busy = false; $schedule->save(); } catch (Exception $e) { $schedule->busy = false; $schedule->save(); throw $e; } } } catch (Exception $e) { Kohana_Log::add("error", (string) $e); } }
function runTask($task_id) { access::verify_csrf(); $task = task::run($task_id); if (!$task->loaded || $task->owner_id != user::active()->id) { access::forbidden(); } print json_encode(array("result" => $task->done ? $task->state : "in_progress", "task" => array("id" => $task->id, "percent_complete" => $task->percent_complete, "type" => $task->get("type"), "post_process" => $task->get("post_process"), "status" => $task->status, "state" => $task->state, "done" => $task->done))); }
// } $data['chapter_id'] = $mapData['chapter']; $data['page'] = $mapData['page']; $data['chapter_info'] = json_encode($data['chapter_info']); $res = $this->get_data('PlayerFB')->update_player_fb($player_id, $data); var_dump($res); } } } } } if (!empty($_POST)) { $player_id = $_POST['player_id']; $task_id = $_POST['task_id']; $obj = new task(); $obj->run($player_id, $task_id); // $obj->open_func($player_id,$task_id); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> Clear Task</TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <style> span{ width:150px;
/** * Run a task. This will trigger the task to do a small amount of work, then it will report * back with status on the task. * @param string $task_id */ public function run($task_id) { access::verify_csrf(); try { $task = task::run($task_id); } catch (Exception $e) { Kohana::log("error", sprintf("%s in %s at line %s:\n%s", $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString())); throw $e; } if ($task->done) { switch ($task->state) { case "success": log::success("tasks", t("Task %task_name completed (task id %task_id)", array("task_name" => $task->name, "task_id" => $task->id)), html::anchor("admin/maintenance", t("maintenance"))); message::success(t("Task completed successfully")); break; case "error": log::error("tasks", t("Task %task_name failed (task id %task_id)", array("task_name" => $task->name, "task_id" => $task->id)), html::anchor("admin/maintenance", t("maintenance"))); message::success(t("Task failed")); break; } print json_encode(array("result" => "success", "task" => array("percent_complete" => $task->percent_complete, "status" => $task->status, "done" => $task->done), "location" => url::site("admin/maintenance"))); } else { print json_encode(array("result" => "in_progress", "task" => array("percent_complete" => $task->percent_complete, "status" => $task->status, "done" => $task->done))); } }
function add_photo($task_id) { access::verify_csrf(); $task = task::run($task_id); if ($task->done) { switch ($task->state) { case "success": message::success(t("Add from server completed")); break; case "error": message::warning(t("Add from server completed with errors")); break; } print json_encode(array("result" => "success", "task" => array("id" => $task->id, "percent_complete" => $task->percent_complete, "status" => $task->status, "done" => $task->done))); } else { print json_encode(array("result" => "in_progress", "task" => array("id" => $task->id, "percent_complete" => $task->percent_complete, "status" => $task->status, "done" => $task->done))); } }
public function run_task($task_id) { access::verify_csrf(); try { $task = task::run($task_id); } catch (Exception $e) { $error_msg = $e->getMessage(); $task->done = true; } if ($task->done) { batch::stop(); $context = unserialize($task->context); switch ($task->state) { case "success": message::success($context["success_msg"]); break; case "error": message::success(empty($error_msg) ? $context["error_msg"] : $error_msg); break; } print json_encode(array("result" => "success", "task" => $task->as_array())); } else { print json_encode(array("result" => "in_progress", "task" => $task->as_array())); } }
static function item_created($item) { if ($item->is_movie()) { transcode::log("Item created - is a movie. Let's create a transcode task or 2.."); $ffmpegPath = module::get_var("transcode", "ffmpeg_path"); $fileObj = self::_getVideoInfo($item->file_path()); transcode::log($fileObj); // Save our needed variables $srcFile = $item->file_path(); $srcWidth = transcode::makeMultipleTwo($fileObj->video->width); $srcHeight = transcode::makeMultipleTwo($fileObj->video->height); $aspect = $srcWidth / $srcHeight; $srcFPS = $fileObj->video->fps; $srcAR = $fileObj->audio->samplerate; if ($srcAR > 44100) { $srcAR = 44100; } $accepted_sample_rates = array(11025, 22050, 44100); if (!in_array($srcAR, $accepted_sample_rates)) { // if the input sample rate isn't an accepted rate, find the next lowest rate that is $below = true; $rate = 0; if ($srcAR < 11025) { $rate = 11025; } else { foreach ($accepted_sample_rates as $r) { transcode::log("testing audio rate '" . $r . "' against input rate '" . $srcAR . "'"); if ($r < $srcAR) { $rate = $r; } } } $srcAR = $rate; } $srcACodec = module::get_var("transcode", "audio_codec"); $heights = array(); if (module::get_var("transcode", "resolution_240p")) { array_push($heights, 240); } if (module::get_var("transcode", "resolution_360p")) { array_push($heights, 360); } if (module::get_var("transcode", "resolution_480p")) { array_push($heights, 480); } if (module::get_var("transcode", "resolution_576p")) { array_push($heights, 576); } if (module::get_var("transcode", "resolution_720p")) { array_push($heights, 720); } if (module::get_var("transcode", "resolution_1080p")) { array_push($heights, 1080); } if (!is_dir(VARPATH . "modules/transcode/flv/" . $item->id)) { @mkdir(VARPATH . "modules/transcode/flv/" . $item->id); } $xtraFlags = module::get_var("transcode", "ffmpeg_flags", ""); foreach ($heights as $destHeight) { transcode::log("srcHeight: " . $srcHeight . ", destheight: " . $destHeight); // don't bother upscaling, there's no advantage to it... if ($destHeight > $srcHeight) { continue; } $destFormat = module::get_var("transcode", "format", "flv"); $destWidth = floor($destHeight * $aspect); if ($destWidth % 2) { $destWidth = ceil($destHeight * $aspect); } transcode::log("destination resolution: " . $destWidth . "x" . $destHeight); $destFile = VARPATH . "modules/transcode/flv/" . $item->id . "/" . $destWidth . "x" . $destHeight . ".flv"; switch ($destHeight) { case 240: $destVB = 128; $srcAB = 16 * ($fileObj->audio->channels ? $fileObj->audio->channels : 2); break; case 360: $destVB = 384; $srcAB = 16 * ($fileObj->audio->channels ? $fileObj->audio->channels : 2); break; case 480: $destVB = 1024; $srcAB = 32 * ($fileObj->audio->channels ? $fileObj->audio->channels : 2); break; case 576: $destVB = 2048; $srcAB = 32 * ($fileObj->audio->channels ? $fileObj->audio->channels : 2); break; case 720: $destVB = 4096; $srcAB = 64 * ($fileObj->audio->channels ? $fileObj->audio->channels : 2); break; case 1080: $destVB = 8192; $srcAB = 64 * ($fileObj->audio->channels ? $fileObj->audio->channels : 2); break; } $destVB *= 1024; $srcAB *= 1024; $cmd = $ffmpegPath . " " . "-i \"" . $srcFile . "\" "; if ($fileObj->audio->has) { $cmd .= "-y -acodec " . $srcACodec . " " . "-ar " . $srcAR . " " . "-ab " . $srcAB . " "; } else { $cmd .= "-an "; } $cmd .= "-vb " . $destVB . " " . "-f " . $destFormat . " " . "-s " . $destWidth . "x" . $destHeight . " " . $xtraFlags . " " . "\"" . $destFile . "\""; transcode::log($cmd); $task_def = Task_Definition::factory()->callback("transcode_task::transcode")->name("Video Transcode to " . $destWidth . "x" . $destHeight)->severity(log::SUCCESS); $task = task::create($task_def, array("ffmpeg_cmd" => $cmd, "width" => $destWidth, "height" => $destHeight, "item_id" => $item->id)); task::run($task->id); } } }
$C_sess->session_constant(); $C_translate = new CORE_translate(); $C_method = new CORE_method(); if (isset($VAR['_login']) && isset($VAR['_username']) && isset($VAR['_password'])) { require_once PATH_CORE . 'login.inc.php'; $C_login = new CORE_login_handler(); $C_login->login($VAR); } elseif (isset($VAR['_logout'])) { require_once PATH_CORE . 'login.inc.php'; $C_login = new CORE_login_handler(); $C_login->logout($VAR); } $C_sess->session_constant_log(); $force = false; $C_auth = new CORE_auth($force); $smarty = new Smarty(); $C_list = new CORE_list(); $C_block = new CORE_block(); require_once PATH_MODULES . 'task/task.inc.php'; $task = new task(); if (!empty($VAR['id'])) { $task->id = $VAR['id']; } elseif (!empty($_SERVER["argv"])) { $task->id = $_SERVER["argv"][0]; } set_time_limit(0); if (@$task->id) { $task->run($VAR, &$task); } else { $task->run_all(); }
/** * Run the task of adding photos */ function run($task_id) { access::verify_csrf(); $task = ORM::factory("task", $task_id); if (!$task->loaded || $task->owner_id != user::active()->id) { access::forbidden(); } $task = task::run($task_id); print json_encode(array("done" => $task->done, "status" => $task->status, "percent_complete" => $task->percent_complete)); }
function add_photo($task_id) { if (!user::active()->admin) { access::forbidden(); } access::verify_csrf(); $task = task::run($task_id); // @todo the task is already run... its a little late to check the access if (!$task->loaded || $task->owner_id != user::active()->id) { access::forbidden(); } if ($task->done) { switch ($task->state) { case "success": message::success(t("Add from server completed")); break; case "error": message::warning(t("Add from server completed with errors")); break; } print json_encode(array("result" => "success", "task" => array("id" => $task->id, "percent_complete" => $task->percent_complete, "status" => $task->status, "done" => $task->done))); } else { print json_encode(array("result" => "in_progress", "task" => array("id" => $task->id, "percent_complete" => $task->percent_complete, "status" => $task->status, "done" => $task->done))); } }
/** * Run the task of creating the theme */ static function run($task_id) { access::verify_csrf(); $task = ORM::factory("task", $task_id); if (!$task->loaded() || $task->owner_id != identity::active_user()->id) { access::forbidden(); } $task = task::run($task_id); // Prevent the JavaScript code from breaking by forcing a period as // decimal separator for all locales with sprintf("%F", $value). json::reply(array("done" => (bool) $task->done, "status" => (string) $task->status, "percent_complete" => sprintf("%F", $task->percent_complete))); }
function runTask($task_id) { access::verify_csrf(); $task = task::run($task_id); print json_encode(array("result" => $task->done ? $task->state : "in_progress", "task" => array("id" => $task->id, "percent_complete" => $task->percent_complete, "type" => $task->get("type"), "post_process" => $task->get("post_process"), "status" => $task->status, "state" => $task->state, "done" => $task->done))); }