Exemplo n.º 1
0
 public function fetchRecord()
 {
     try {
         $lock = Lock::acquire('getPendingRecord');
         if (($r = $this->getPendingRecord()) == NULL) {
             throw new fExpectedException('No pending record.');
         }
         $p = $r->getProblem();
         $r->setJudgeStatus(JudgeStatus::WAITING);
         $r->store();
         Lock::release($lock);
         echo json_encode(array('id' => $r->getId(), 'problem_id' => $p->getId(), 'code_language' => $r->getLanguageName(), 'code' => base64_encode($r->getSubmitCode()), 'memoryLimit' => $p->getMemoryLimit(), 'timeLimit' => $p->getTimeLimit(), 'caseScore' => $p->getCaseScore(), 'caseCount' => $p->getCaseCount(), 'Timestamp' => $p->getLastModified()), JSON_NUMERIC_CHECK);
     } catch (fException $e) {
         echo -1;
     }
 }
Exemplo n.º 2
0
        }
    } else {
        foreach (array_keys($config) as $key) {
            if (isset($_GET[$key])) {
                $config[$key] = $_GET[$key];
            }
        }
    }
    return $config;
}
$config = getParams();
// if requested, clear the lock
if ($config['fix-lock']) {
    if (Lock::release('process_mail_queue')) {
        echo "The lock file was removed successfully.\n";
    }
    exit(0);
}
if (!Lock::acquire('process_mail_queue')) {
    $pid = Lock::getProcessID('process_mail_queue');
    fwrite(STDERR, "ERROR: There is already a process (pid={$pid}) of this script running.");
    fwrite(STDERR, "If this is not accurate, you may fix it by running this script with '--fix-lock' as the only parameter.\n");
    exit(1);
}
// handle only pending emails
$limit = 50;
Mail_Queue::send('pending', $limit);
// handle emails that we tried to send before, but an error happened...
$limit = 50;
Mail_Queue::send('error', $limit);
Lock::release('process_mail_queue');
Exemplo n.º 3
0
// | This program is distributed in the hope that it will be useful,      |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
// | GNU General Public License for more details.                         |
// |                                                                      |
// | You should have received a copy of the GNU General Public License    |
// | along with this program; if not, write to:                           |
// |                                                                      |
// | Free Software Foundation, Inc.                                       |
// | 51 Franklin Street, Suite 330                                        |
// | Boston, MA 02110-1301, USA.                                          |
// +----------------------------------------------------------------------+
// | Authors: Bryan Alsdorf <*****@*****.**>                          |
// +----------------------------------------------------------------------+
ini_set('memory_limit', '1024M');
require_once dirname(__FILE__) . '/../init.php';
// if requested, clear the lock
if (in_array('--fix-lock', $argv)) {
    if (Lock::release('truncate_mail_queue')) {
        echo "The lock file was removed successfully.\n";
    }
    exit(0);
}
if (!Lock::acquire('truncate_mail_queue')) {
    $pid = Lock::getProcessID('truncate_mail_queue');
    fwrite(STDERR, "ERROR: There is already a process (pid={$pid}) of this script running.");
    fwrite(STDERR, "If this is not accurate, you may fix it by running this script with '--fix-lock' as the only parameter.\n");
    exit(1);
}
Mail_Queue::truncate();
Lock::release('truncate_mail_queue');
Exemplo n.º 4
0
// | 51 Franklin Street, Suite 330                                          |
// | Boston, MA 02110-1301, USA.                                          |
// +----------------------------------------------------------------------+
// | Authors: João Prado Maia <*****@*****.**>                             |
// +----------------------------------------------------------------------+
require_once dirname(__FILE__) . '/../init.php';
// if requested, clear the lock
if (in_array('--fix-lock', $argv)) {
    if (Lock::release('check_reminders')) {
        echo "The lock file was removed successfully.\n";
    }
    exit;
}
// acquire a lock to prevent multiple scripts from
// running at the same time
if (!Lock::acquire('check_reminders')) {
    echo 'Error: Another instance of the script is still running. ' . "If this is not accurate, you may fix it by running this script with '--fix-lock' " . "as the only parameter.\n";
    exit;
}
if (in_array('--debug', $argv)) {
    Reminder::$debug = true;
}
/*
1 - Get list of reminders with all of its actions
2 - Loop through each reminder level and build the SQL query
3 - If query returns TRUE, then run the appropriate action
4 - Get the list of actions
5 - Calculate which action need to be performed, if any
6 - Avoid repeating reminder actions, so first check if the last triggered action is the same one as "now"
7 - Perform action
8 - Continue to next reminder level
Exemplo n.º 5
0
assertEquals("ș'aibă", FlexStringUtil::placeAccent("șaibă", 2, 'a'));
assertEquals("ș'aibă", FlexStringUtil::placeAccent("șaibă", 3, 'a'));
assertEquals("șa'ibă", FlexStringUtil::placeAccent("șaibă", 2, 'i'));
assertEquals("șa'ibă", FlexStringUtil::placeAccent("șaibă", 3, 'i'));
assertEquals("unfuckingbelievable", FlexStringUtil::insert("unbelievable", "f*****g", 2));
assertEquals("abcdef", FlexStringUtil::insert("cdef", "ab", 0));
assertEquals("abcdef", FlexStringUtil::insert("abcd", "ef", 4));
assertEquals('mamă      ', AdminStringUtil::padRight('mamă', 10));
assertEquals('mama      ', AdminStringUtil::padRight('mama', 10));
assertEquals('ăâîșț   ', AdminStringUtil::padRight('ăâîșț', 8));
assertEquals('ăâîșț', AdminStringUtil::padRight('ăâîșț', 5));
assertEquals('ăâîșț', AdminStringUtil::padRight('ăâîșț', 3));
assertEqualArrays(array('c', 'a', 'r'), AdminStringUtil::unicodeExplode('car'));
assertEqualArrays(array('ă', 'a', 'â', 'ș', 'ț'), AdminStringUtil::unicodeExplode('ăaâșț'));
assertEqualArrays(array(1, 5, 10), util_intersectArrays(array(1, 3, 5, 7, 9, 10), array(1, 2, 4, 5, 6, 8, 10)));
assertEqualArrays(array(), util_intersectArrays(array(2, 4, 6, 8), array(1, 3, 5, 7)));
assert(!Lock::release('test'));
assert(!Lock::exists('test'));
assert(Lock::acquire('test'));
assert(Lock::exists('test'));
assert(!Lock::acquire('test'));
assert(Lock::release('test'));
assert(!Lock::exists('test'));
assert(!Lock::release('test'));
assertEquals(0, util_findSnippet(array(array(1, 2, 10))));
assertEquals(1, util_findSnippet(array(array(1, 2, 10), array(5, 6, 9))));
assertEquals(2, util_findSnippet(array(array(1, 2, 10), array(5, 6, 8))));
assertEquals(4, util_findSnippet(array(array(1, 2, 10), array(6, 20), array(8, 15))));
assertEquals('$abc$ @def@', AdminStringUtil::formatLexem('$abc$ @def@'));
// This is intentional -- lexem formatting is very lenient.
assertEquals("m'amă m'are", AdminStringUtil::formatLexem("m'am~a máre  "));
Exemplo n.º 6
0
                $lockfile = 'download_emails_' . $ema_id;
                if (Lock::release($lockfile)) {
                    msg("Removed lock file '{$lockfile}'.");
                }
            }
        }
    } else {
        $lockfile = 'download_emails_' . $account_id;
        if (Lock::release($lockfile)) {
            msg("Removed lock file '{$lockfile}'.");
        }
    }
    exit(0);
}
// check if there is another instance of this script already running
if (!Lock::acquire('download_emails_' . $account_id)) {
    if (SAPI_CLI) {
        fatal('Another instance of the script is still running for the specified account.', "If this is not accurate, you may fix it by running this script with '--fix-lock'", "as the 4th parameter or you may unlock ALL accounts by running this script with '--fix-lock'", 'as the only parameter.');
    } else {
        fatal('Another instance of the script is still running for the specified account. ', "If this is not accurate, you may fix it by running this script with 'fix-lock=1'", "in the query string or you may unlock ALL accounts by running this script with 'fix-lock=1'", 'as the only parameter.');
    }
    exit;
}
// clear the lock in all cases of termination
function cleanup_lock()
{
    global $account_id;
    Lock::release('download_emails_' . $account_id);
}
register_shutdown_function('cleanup_lock');
$account = Email_Account::getDetails($account_id);
Exemplo n.º 7
0
}
require_once APP_CONFIG_PATH . '/irc_config.php';
// if requested, clear the lock
if (in_array('--fix-lock', $argv)) {
    Lock::release('irc_bot');
    echo "The lock file was removed successfully.\n";
    exit;
}
if (in_array('--check-process', $argv)) {
    $check = true;
} else {
    $check = false;
}
// acquire a lock to prevent multiple scripts from
// running at the same time
if (!Lock::acquire('irc_bot', $check)) {
    echo 'Error: Another instance of the script is still running. ', "If this is not accurate, you may fix it by running this script with '--fix-lock' ", "as the only parameter.\n";
    exit;
}
$auth = array();
// map project_id => channel(s)
// TODO: Map old config to new config
$channels = array();
foreach ($irc_channels as $proj => $chan) {
    $proj_id = Project::getID($proj);
    // we need to map old configs with just channels to new config with categories as well
    if (!is_array($chan)) {
        // old config, one channel
        $options = array($chan => array(APP_EVENTUM_IRC_CATEGORY_DEFAULT));
    } elseif (isset($chan[0]) and !is_array($chan[0])) {
        // old config with multiple channels
Exemplo n.º 8
0
 /**
  * acquire a lock to prevent multiple scripts from running at the same time.
  * if the lock was acquired, setup event handler to release lock on shutdown
  *
  * @param bool|true $check
  * @return bool
  */
 public function lock($check = true)
 {
     $locked = Lock::acquire($this->config['lock'], $check);
     if (!$locked) {
         return $locked;
     }
     // setup signal handler to be able to remove lock and shutdown cleanly
     $bot = $this;
     $irc =& $this->irc;
     $handler = function ($signal = null) use($bot, &$irc) {
         $bot->shutdown = true;
         // if stream_select receives signal, SmartIRC will automatically retry
         // disable reconnect, and die
         // this is not needed if we are connected,
         // but unable to query such state, all variables and methods related to it are not public
         $irc->setAutoRetry(false);
         if ($signal) {
             $irc->log(SMARTIRC_DEBUG_NOTICE, "Got signal[{$signal}]; shutdown", __FILE__, __LINE__);
             $irc->quit('Terminated');
         } else {
             $irc->log(SMARTIRC_DEBUG_NOTICE, 'Shutdown handler', __FILE__, __LINE__);
             $irc->quit('Bye');
         }
         // QUIT has no effect if not connected
         $irc->disconnect();
         $bot->unlock();
     };
     if ($this->have_pcntl) {
         pcntl_signal(SIGINT, $handler);
         pcntl_signal(SIGTERM, $handler);
     } else {
         error_log('pcntl extension not present, signal processing not enabled');
     }
     // NOTE: signal handler is not enough because stream_select() also catches the signals and aborts the process
     // so register the shutdown handler as well
     register_shutdown_function($handler);
     return $locked;
 }
Exemplo n.º 9
0
<?php

/**
 *
 */
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
require __DIR__ . '/../classes/Lock.class.php';
$lock = new Lock('test');
if ($lock->exists()) {
    die("Lock '" . $lock->getId() . "' exists\n");
}
echo "Acquire lock...\n";
$lock->acquire();
echo "Doing smth for 10 seconds...\n";
echo "During this time, another instance of this script will not run\n";
sleep(10);
echo "Releasing lock...\n";
echo $lock->release();
Exemplo n.º 10
0
$username = '';
$password = '';
// ============================================
// ============================================
// NO NEED TO UPDATE ANYTHING BELOW THIS LINE
// ============================================
// ============================================
// if requested, clear the lock
if (in_array('--fix-lock', @$HTTP_SERVER_VARS['argv'])) {
    Lock::release('irc_bot');
    echo "The lock file was removed successfully.\n";
    exit;
}
// acquire a lock to prevent multiple scripts from
// running at the same time
if (!Lock::acquire('irc_bot')) {
    echo "Error: Another instance of the script is still running. " . "If this is not accurate, you may fix it by running this script with '--fix-lock' " . "as the only parameter.\n";
    exit;
}
$auth = array();
class Eventum_Bot
{
    function _isAuthenticated(&$irc, &$data)
    {
        global $auth;
        if (in_array($data->nick, array_keys($auth))) {
            return true;
        } else {
            $this->sendResponse($irc, $data->nick, 'Error: You need to be authenticated to run this command.');
            return false;
        }
Exemplo n.º 11
0
 /**
  * Checks whether it is safe or not to run the mail queue script.
  *
  * @access  public
  * @return  boolean
  */
 function isSafeToRun()
 {
     return Lock::acquire('process_mail_queue');
 }
Exemplo n.º 12
0
<?php

require_once __DIR__ . '/../phplib/util.php';
ini_set('max_execution_time', '3600');
ini_set('memory_limit', '256M');
assert_options(ASSERT_BAIL, 1);
log_scriptLog('Running rebuildFullTextIndex.php.');
if (!Lock::acquire(LOCK_FULL_TEXT_INDEX)) {
    OS::errorAndExit('Lock already exists!');
    exit;
}
log_scriptLog("Clearing table FullTextIndex.");
db_execute('truncate table FullTextIndex');
$stopWordForms = array_flip(db_getArray('select distinct i.formNoAccent ' . 'from Lexem l, LexemModel lm, InflectedForm i ' . 'where l.id = lm.lexemId ' . 'and lm.id = i.lexemModelId ' . 'and l.stopWord'));
$ifMap = array();
$dbResult = db_execute('select id, internalRep from Definition where status = 0');
$numDefs = $dbResult->rowCount();
$defsSeen = 0;
$indexSize = 0;
$fileName = tempnam(Config::get('global.tempDir'), 'index_');
$handle = fopen($fileName, 'w');
log_scriptLog("Writing index to file {$fileName}.");
DebugInfo::disable();
foreach ($dbResult as $dbRow) {
    $words = extractWords($dbRow[1]);
    foreach ($words as $position => $word) {
        if (!isset($stopWordForms[$word])) {
            if (!array_key_exists($word, $ifMap)) {
                cacheWordForm($word);
            }
            if (array_key_exists($word, $ifMap)) {