Skip to content

Commit

Permalink
ARLO-38: Fixing instance job not found issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ojnadjarm committed Nov 28, 2023
1 parent 8cf5a05 commit 9167d73
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
53 changes: 33 additions & 20 deletions classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,12 @@ public static function run_associate_all() {
*
* @param $instanceid
* @param $full
* @return void
* @param $trace
* @return bool
* @throws \coding_exception
* @throws \dml_exception
*/
public static function run_instance_jobs($instanceid, $full = false) {
public static function run_instance_jobs($instanceid, $full = false, $trace = null) {
global $DB;

$membershipsjobpersistent = \enrol_arlo\local\persistent\job_persistent::get_record(
Expand All @@ -433,25 +434,37 @@ public static function run_instance_jobs($instanceid, $full = false) {
'instanceid' => $instanceid
]
);
if ($full) {
$membershipsjobpersistent->set('lastsourceid', 0);
$membershipsjobpersistent->set('lastsourcetimemodified', '1970-01-01T00:00:00Z');
$membershipsjobpersistent->set('timelastrequest', 0);
$membershipsjobpersistent->save();
$DB->set_field('enrol_arlo_registration', 'updatesource', 1, ['enrolid' => $instanceid]);

if (!empty($membershipsjobpersistent)) {
if ($full) {
$membershipsjobpersistent->set('lastsourceid', 0);
$membershipsjobpersistent->set('lastsourcetimemodified', '1970-01-01T00:00:00Z');
$membershipsjobpersistent->set('timelastrequest', 0);
$membershipsjobpersistent->save();
$DB->set_field('enrol_arlo_registration', 'updatesource', 1, ['enrolid' => $instanceid]);
}
$membershipsjob = \enrol_arlo\local\factory\job_factory::create_from_persistent($membershipsjobpersistent);
$membershipstatus = $membershipsjob->run();
} else {
if (!empty($trace)) {
$trace->output("No memberships job found for instance {$instanceid}");
} else {
throw new moodle_exception('intancejoberror','enrol_arlo');
}
}
$membershipsjob = \enrol_arlo\local\factory\job_factory::create_from_persistent($membershipsjobpersistent);
$status = $membershipsjob->run();
// Run outcomes job.
$outcomesjobpersistent = \enrol_arlo\local\persistent\job_persistent::get_record(
[
'area' => 'enrolment',
'type' => 'outcomes',
'instanceid' => $instanceid
]
);
$outcomesjob = \enrol_arlo\local\factory\job_factory::create_from_persistent($outcomesjobpersistent);
$status = $outcomesjob->run();


if (!empty($outcomesjobpersistent)) {
$outcomesjob = \enrol_arlo\local\factory\job_factory::create_from_persistent($outcomesjobpersistent);
$outcomestatus = $outcomesjob->run();
} else {
if (!empty($trace)) {
$trace->output("No outcomes job found for instance {$instanceid}");
} else {
throw new moodle_exception('intancejoberror','enrol_arlo');
}
}
return !empty($membershipstatus) && !empty($outcomestatus);
}

}
12 changes: 8 additions & 4 deletions classes/local/job/memberships_job.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,10 @@ public static function sync_memberships($trace) {
'customchar2' => arlo_type::EVENT,
'customchar3' => $missedevent
])) {
api::run_instance_jobs($enrolmentinstance->id);
self::remove_missed_resource(arlo_type::EVENT, $missedevent);
$jobdone = api::run_instance_jobs($enrolmentinstance->id, false, $trace);
if ($jobdone) {
self::remove_missed_resource(arlo_type::EVENT, $missedevent);
}
}
}
}
Expand All @@ -268,8 +270,10 @@ public static function sync_memberships($trace) {
'customchar2' => arlo_type::EVENT,
'customchar3' => $missedonline
])) {
api::run_instance_jobs($enrolmentinstance->id);
self::remove_missed_resource(arlo_type::ONLINEACTIVITY, $missedonline);
$jobdone = api::run_instance_jobs($enrolmentinstance->id, false, $trace);
if ($jobdone) {
self::remove_missed_resource(arlo_type::ONLINEACTIVITY, $missedonline);
}
}
}
}
Expand Down

0 comments on commit 9167d73

Please sign in to comment.