svickers@packetmedia.co.uk

Custom scheduler job help needed

Discussion created by svickers@packetmedia.co.uk on Feb 28, 2017
Latest reply on Mar 7, 2017 by Francesca Shiekh

Hi,

I have created a custom scheduler Job using a blog I found and have adapted it slightly as it was using get_full_list, to update calculated fields nightly without affecting modified dates the code is as follows:

 

<?php

//add the job key to the list of job strings
array_push($job_strings, 'custom_job');

function custom_job()
{
//custom job code
require_once('include/SugarQuery/SugarQuery.php');
$bean = BeanFactory::getBean('Cases');
$SugarQuery = new SugarQuery();
$sugarQuery->select(array('status'));
$sugarQuery->from($bean,array('team_security' => false));
$sugarQuery->where()->equals('status','new');
$result = $sugarQuery->execute();


if( $result != null ) {
foreach($result as $b) {
// These lines prevent the modified date and user from being changed.
$b->update_date_modified = false;
$b->update_modified_by = false;
$b->tracker_visibility = false;
$b->in_workflow = true;
$b->save();
$cnt++;
}
}
print "Finished updating: $cnt records.\n<br>";

//return true for completed
return true;
}

 

However, I am getting an error in the Sugar logs:

Tue Feb 28 09:51:58 2017 [5115][1][FATAL] [SessionLock] Session lock was held for 5 seconds which is longer than the maximum of 1 seconds. Request details: SERVER_NAME: ...., SERVER_ADDR: Not set, SCRIPT_FILENAME: /mnt/sugar/7.8.0.1/ent/cron.php, REQUEST_METHOD: Not set, SCRIPT_NAME: /mnt/sugar/7.8.0.1/ent/cron.php, REQUEST_URI: , QUERY_STRING: Not set Tue Feb 28 09:51:59 2017 [5115][1][FATAL] Job 87bc8bea-fd9b-11e6-8219-062520151959 (Test Custom Job) failed in CRON run

We are on Sugar Enterprise Edition (Ondemand - The latest version), does anyone have any ideas where I have gone wrong, I apologise in advance, my development knowledge is limited.

 

Thanks in advance for any assistance, its greatly appreciated!

 

SV

Outcomes