job_manager.php
Table of Contents
Functions
- job_manager() : mixed
- here is our buddy the job manager, made to be run as a command an working with "jobs" database as a job pile.
- new_job() : void
- to add a new job in "jobs" database pile
- cancel_job() : void
- Cancel a job and move if from db to history
- set_status_job() : void
- Change the status of a job in the pile.
- get_job_progress() : string
- Get the progression of a job
- job_loop() : void
- The job loop will run until there is no more job to do, so it must be started at start or the server and it will go on infine loop waiting for job to execute.
Functions
job_manager()
here is our buddy the job manager, made to be run as a command an working with "jobs" database as a job pile.
job_manager(mixed $argv) : mixed
arguments : -k , to identify the job -C , callback when command is done -c , the command to execute -f , path to the instance -a , action for the job manager (new, progress or cancel)
exemples :
-
add a job : $job_manager_call='php /home/helphp/utils/job_manager.php -a"new" -f"'.$from.'" -c"'.$cmd.'" -C"'.$callback.'" -k"'.$key.'"';
-
get progress : $job_manager_call='php /home/helphp/utils/job_manager.php -a"progress" -f"'.$from.'" -k"'.$key.'"';
-
cancel : $job_manager_call='php /home/helphp/utils/job_manager.php -a"cancel" -f"'.$from.'" -k"'.$key.'"';
must be followed by : exec($job_manager_call);
Parameters
- $argv : mixed
new_job()
to add a new job in "jobs" database pile
new_job(mixed $from, mixed $command, mixed $callback, mixed $key) : void
Parameters
- $from : mixed
-
origine identifier
- $command : mixed
-
to exec
- $callback : mixed
-
ta call back after exec
- $key : mixed
-
the key identifier that permit to follow th process.
cancel_job()
Cancel a job and move if from db to history
cancel_job(mixed $from, mixed $key) : void
Parameters
- $from : mixed
-
origine identifier
- $key : mixed
-
indentifier of the job to cancel.
set_status_job()
Change the status of a job in the pile.
set_status_job(mixed $from, mixed $key, mixed $status) : void
Parameters
- $from : mixed
-
origine identifier
- $key : mixed
-
indentifier of the job
- $status : mixed
-
possible values :
- 0 undone
- 1 in progress
- 2 done
- 3 error
get_job_progress()
Get the progression of a job
get_job_progress(mixed $from, mixed $key) : string
Parameters
- $from : mixed
-
origine identifier
- $key : mixed
-
indentifier of the job
Return values
string —messages / echo from the process if it got status = 1 (1 in progress)
- status 0 : it will return "wait"
- status 2 : "ok!" because finished
- status 3 : "err" an error happenned.
job_loop()
The job loop will run until there is no more job to do, so it must be started at start or the server and it will go on infine loop waiting for job to execute.
job_loop() : void