/** * Run job from queue * @param string $session * @param string $jobid * @param string $clientid */ public function job_queue_run($session, $jobid, $clientid) { $GLOBALS['log']->info('Begin: SugarWebServiceImpl->job_queue_run'); $error = new SoapError(); if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', 'read', 'no_access', $error)) { $GLOBALS['log']->info('End: SugarWebServiceImpl->job_queue_run denied.'); return; } $GLOBALS['log']->debug('Starting job $jobid execution as $clientid'); require_once 'modules/SchedulersJobs/SchedulersJob.php'; $result = SchedulersJob::runJobId($jobid, $clientid); $GLOBALS['log']->info('End: SugarWebServiceImpl->job_queue_run'); if ($result === true) { return array("results" => true); } else { return array("results" => false, "message" => $result); } }
if (substr($sapi_type, 0, 3) != 'cli') { sugar_die("run_job.php is CLI only."); } if ($argc < 3 || empty($argv[1]) || empty($argv[2])) { sugar_die("run_job.php requires job ID and client ID as parameters."); } if (empty($current_language)) { $current_language = $sugar_config['default_language']; } $app_list_strings = return_app_list_strings_language($current_language); $app_strings = return_application_language($current_language); $current_user = new User(); $current_user->getSystemUser(); Log::debug('Starting job {$argv[1]} execution as ${argv[2]}'); require_once 'modules/SchedulersJobs/SchedulersJob.php'; $result = SchedulersJob::runJobId($argv[1], $argv[2]); if (is_string($result)) { // something wrong happened echo $result; echo "\n"; $result = false; } sugar_cleanup(false); // some jobs have annoying habit of calling sugar_cleanup(), and it can be called only once // but job results can be written to DB after job is finished, so we have to disconnect here again // just in case we couldn't call cleanup if (class_exists('DBManagerFactory')) { $db = DBManagerFactory::getInstance(); $db->disconnect(); } exit($result ? 0 : 1);
public function testJobClients() { $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser(); $job = $this->createJob(array("name" => "Test Func Clients", "status" => SchedulersJob::JOB_STATUS_RUNNING, "target" => "function::SchedulersJobsTest::staticJobFunctionInternal", "client" => "UnitTests", "assigned_user_id" => $GLOBALS['current_user']->id)); $res = SchedulersJob::runJobId($job->id, "UnitTests"); $job->retrieve($job->id); $this->assertTrue($res, "Bad result from runJobId"); $this->assertEquals(SchedulersJob::JOB_SUCCESS, $job->resolution, "Wrong resolution"); $this->assertEquals(SchedulersJob::JOB_STATUS_DONE, $job->status, "Wrong status"); $this->assertContains("Job OK", $job->message); // wrong client $job = $this->createJob(array("name" => "Test Func Clients 2", "status" => SchedulersJob::JOB_STATUS_RUNNING, "target" => "function::SchedulersJobsTest::staticJobFunctionInternal", "client" => "UnitTests", "assigned_user_id" => $GLOBALS['current_user']->id)); $res = SchedulersJob::runJobId($job->id, "UnitTests2"); $this->assertFalse($res === true, "Bad result from runJobId"); // wrong ID $res = SchedulersJob::runJobId("where's waldo?", "UnitTests2"); $this->assertFalse($res === true, "Bad result from runJobId"); }
public function testrunJobId() { //test with invalid job id $result = SchedulersJob::runJobId('1'); $this->assertEquals('Job 1 not found.', $result); //test with valid job id $schedulersJob = new SchedulersJob(); $schedulersJob->status = SchedulersJob::JOB_STATUS_DONE; $schedulersJob->save(); $result = SchedulersJob::runJobId($schedulersJob->id); $this->assertEquals('Job ' . $schedulersJob->id . ' is not marked as running.', $result); //test with valid job id and status but mismatch client $schedulersJob->client = 'client'; $schedulersJob->status = SchedulersJob::JOB_STATUS_RUNNING; $schedulersJob->save(); $result = SchedulersJob::runJobId($schedulersJob->id, 'test_client'); $this->assertEquals('Job ' . $schedulersJob->id . ' belongs to another client, can not run as test_client.', $result); $schedulersJob->mark_deleted($schedulersJob->id); }