You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
831 B
TypeScript
23 lines
831 B
TypeScript
2 years ago
|
import { isEmpty, isString } from 'lodash';
|
||
|
import { ConfigurationSyncJob } from './jobs/ConfigurationSyncJob';
|
||
|
import { Persistedjob, PersistedJobType, SerializedPersistedJob } from './PersistedJob';
|
||
|
|
||
|
export function persistedJobFromData(data: SerializedPersistedJob): Persistedjob | null {
|
||
|
if (!data || isEmpty(data.jobType) || !isString(data?.jobType)) {
|
||
|
return null;
|
||
|
}
|
||
|
const jobType: PersistedJobType = data.jobType as PersistedJobType;
|
||
|
switch (jobType) {
|
||
|
case 'ConfigurationSyncJobType':
|
||
|
return new ConfigurationSyncJob({
|
||
|
maxAttempts: data.maxAttempts,
|
||
|
identifier: data.identifier,
|
||
|
nextAttemptTimestamp: data.nextAttemptTimestamp,
|
||
|
currentRetry: data.currentRetry,
|
||
|
});
|
||
|
default:
|
||
|
console.warn('unknown persisted job type:', jobType);
|
||
|
return null;
|
||
|
}
|
||
|
}
|