Skip to content

Commit 45aade9

Browse files
committed
feat: add concernedToName option for job execution in BackendsService
- Introduced a new `concernedToName` property in the ExecuteJobOptions interface to enhance job execution context. - Updated BackendsService to utilize `concernedToName` for improved identity handling during job creation. - Enhanced error handling in LifecycleHooksService to ensure robust processing of identity lifecycle updates.
1 parent d0f468d commit 45aade9

4 files changed

Lines changed: 57 additions & 29 deletions

File tree

apps/api/src/core/backends/_interfaces/execute-job-options.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface ExecuteJobOptions {
1010
updateStatus?: boolean;
1111
switchToProcessing?: boolean;
1212
comment?: string;
13+
concernedToName?: string;
1314
targetState?: any;
1415
dataState?: any;
1516
task?: Types.ObjectId;

apps/api/src/core/backends/backends.service.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ export class BackendsService extends AbstractQueueProcessor {
298298
...options,
299299
updateStatus: true,
300300
task: task._id as unknown as Types.ObjectId,
301+
concernedToName: identity.identity.inetOrgPerson?.cn,
301302
},
302303
);
303304
result[identity.identity._id] = executedJob;
@@ -530,8 +531,20 @@ export class BackendsService extends AbstractQueueProcessor {
530531
let jobStore: Document<Jobs> = null;
531532
const disableLogs = options?.disableLogs === true;
532533
if (!disableLogs || !!concernedTo) {
533-
const identity =
534-
!disableLogs && concernedTo ? await this.identitiesService.findById<Identities>(concernedTo) : null;
534+
let concernedToName = options?.concernedToName;
535+
if (!concernedToName && !disableLogs && concernedTo) {
536+
concernedToName =
537+
payload?.after?.inetOrgPerson?.cn ??
538+
payload?.identity?.inetOrgPerson?.cn ??
539+
payload?.inetOrgPerson?.cn;
540+
}
541+
if (!concernedToName && !disableLogs && concernedTo) {
542+
const identity = await this.identitiesService.model
543+
.findById(concernedTo)
544+
.select('inetOrgPerson.cn')
545+
.lean();
546+
concernedToName = identity?.inetOrgPerson?.cn;
547+
}
535548
jobStore = await this.jobsService.create<Jobs>({
536549
jobId: job.id,
537550
action: actionType,
@@ -540,7 +553,7 @@ export class BackendsService extends AbstractQueueProcessor {
540553
? {
541554
$ref: 'identities',
542555
id: concernedTo,
543-
name: identity?.inetOrgPerson?.cn,
556+
name: concernedToName,
544557
}
545558
: null,
546559
comment: options?.comment,

apps/api/src/management/lifecycle/lifecycle-hooks.service.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -333,21 +333,25 @@ export class LifecycleHooksService extends AbstractLifecycleService {
333333
this.logger.verbose(`identities process request`, JSON.stringify(req, null, 2));
334334

335335
for (const identity of identities) {
336-
const hasMutation = hasLifecycleMutation(resolvedMutation);
337-
const updated = await this.identitiesService.model.findOneAndUpdate(
338-
{ _id: identity._id },
339-
{
340-
$set: {
341-
...resolvedMutation,
342-
lifecycle: idRule.target,
343-
lastLifecycleUpdate: new Date(),
344-
...(hasMutation ? { state: IdentityState.TO_SYNC } : {}),
336+
try {
337+
const hasMutation = hasLifecycleMutation(resolvedMutation);
338+
const updated = await this.identitiesService.model.findOneAndUpdate(
339+
{ _id: identity._id },
340+
{
341+
$set: {
342+
...resolvedMutation,
343+
lifecycle: idRule.target,
344+
lastLifecycleUpdate: new Date(),
345+
...(hasMutation ? { state: IdentityState.TO_SYNC } : {}),
346+
},
345347
},
346-
},
347-
{ new: true },
348-
);
348+
{ new: true },
349+
);
350+
351+
if (!updated) {
352+
continue;
353+
}
349354

350-
if (updated) {
351355
await this.create({
352356
refId: identity._id,
353357
lifecycle: idRule.target,
@@ -357,13 +361,23 @@ export class LifecycleHooksService extends AbstractLifecycleService {
357361
if (hasMutation) {
358362
await this.backendsService.lifecycleChangedIdentities(
359363
[{ id: updated._id.toString(), before: identity, after: updated }],
360-
{ targetState: IdentityState.TO_SYNC },
364+
{
365+
async: true,
366+
updateStatus: false,
367+
targetState: IdentityState.TO_SYNC,
368+
},
361369
);
362370
}
363371

364372
this.logger.log(
365373
`Identity <${identity._id}> updated to lifecycle <${idRule.target}> by trigger from source <${idRule.sources}>`,
366374
);
375+
} catch (error) {
376+
this.logger.error(
377+
`Error processing identity <${identity._id}> for lifecycle trigger in source <${idRule.sources}>:`,
378+
error?.message,
379+
error?.stack,
380+
);
367381
}
368382
}
369383
} catch (error) {

apps/web/src/pages/settings/cron.vue

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@
5555
@click='toggleCronEnabled(row)'
5656
)
5757
q-tooltip.text-body2 {{ row.enabled ? 'Désactiver' : 'Activer' }} la tâche
58-
//- q-btn(
59-
//- :disable='!hasPermission("/core/cron", "update")'
60-
//- :loading='!!cronRunLoading[row.name]'
61-
//- color='purple'
62-
//- icon='mdi-play-circle-outline'
63-
//- size='12px'
64-
//- flat
65-
//- round
66-
//- dense
67-
//- @click='runCronImmediately(row)'
68-
//- )
69-
//- q-tooltip.text-body2 Exécuter immédiatement
58+
q-btn(
59+
:disable='!hasPermission("/core/cron", "update")'
60+
:loading='!!cronRunLoading[row.name]'
61+
color='purple'
62+
icon='mdi-play-circle-outline'
63+
size='12px'
64+
flat
65+
round
66+
dense
67+
@click='runCronImmediately(row)'
68+
)
69+
q-tooltip.text-body2 Exécuter immédiatement
7070
q-btn(
7171
:disable='!hasPermission("/core/cron", "read")'
7272
color='primary'

0 commit comments

Comments
 (0)