class Cron_Lock

The simplest locking technique for blocking multiple concurrent tasks run by the Scheduler.  As soon as one task has been run, a lock file is created to prevent running another process.  The lock has its validity period, which is summed up from the time of the last update and the time passed before interception. 

class Cron_Lock
{
/**
 * Default configuration
 * time_limit - execution time limit
 * intercept_limit - time period between the last update and interception
 * locks_dir - path to the lock file directory
 * @var array
 */
protected $config 

/**
 * Starting time
 * @var integer
 */
protected $startTime = 0;

/**
 * Application name
 * @var unknown
 */
protected $task= 'task';

/**
 * Path to the lock file
 * @var string
 */
protected $lockFile = false;

/**
 * Logging adapter
 * @var Log
 */
protected $logsAdapter = false;

/**
 * Builder settings are applied as an array: name => value, 
 * time_limit - execution time limit (in seconds)
 * intercept_limit - time period between the last update and interception (in seconds)
 * locks_dir - path to the lock file directory
 * @param array $config (time_limit,intercept_limit,locks_dir)
 */
public function __construct(array $config = array())

/**
 * Set execution time limit
 * @param integer $limit
 */
public function setTimeLimit($limit)

/**
 * Set path to the lock file directory
 * @param string $path
 * @throws Exception
 */
public function setLocksDir($path)

/**
 * Set time period between the last update and interception (in seconds)
 * - the period of time passed after the lock file last update before the moment of interception.
 * @param integer $limit
 */
public function setInterceptTimeout($limit)

/**
 * Set logging adapter
 * @param Log $log
 */
public function setLogsAdapter(Log $log)

/**
 * Run task
 * Returns true if lock is successfully set up, allows for task processing.
 * Returns false in case there already exists a lock file and its validity time has not yet expired 
 * (the process is already started)
 * @param string $taskName - the task name used when creating a lock file
 * @return boolean
 */
public function launch($taskName)

/**
 * Check for a lock
 * @return boolean
 */
public function isLocked()

/**
 * Create a lock for the current task
 * @return boolean
 */
public function setLock()

/**
 * Update lock data
 * @return boolean
 */
public function sync()

/**
 * Remove lock file
 * @return boolean
 */
public function releaseLock()

/**
 * Send log message
 * @param string $message
 */
public function log($message)

/**
 * Get execution time limit
 * @return integer
 */
public function getTimeLimit()

/**
 * Get task starting time
 * @return integer
 */
public function getStartTime()

/**
 * Check if the execution time limit has been reached
 * @return boolean
 */
public function isTimeLimitReached()

/**
 * Check the execution time limit and close the application if the time limit has been reached
 */
public function checkTimeLimit()

/**
 * Finish task
 */
public function finish()
}

comments powered by Disqus