Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cron Processor #168

Closed
jphgardner02 opened this issue Sep 18, 2019 · 3 comments
Closed

Cron Processor #168

jphgardner02 opened this issue Sep 18, 2019 · 3 comments
Labels
meta This is not directly related to the sources question Further information is requested

Comments

@jphgardner02
Copy link

Hi,

I am looking at using this library to allow my application to support background jobs.

Some jobs will be added to the Queue and others will need to be ran on a Cron Specification.

At the moment i am struggling to correctly configure a Cron Process.

`@Processor({ name: 'store' })
export class ScheduleService {

constructor(private readonly _http: HttpService,
			private readonly _connectionManager: ConnectionManagerService,
			private readonly _sanctionService: SanctionsService) {
}

@Process({ name: 'importSanctionList' })
/*@Cron('59 23 * * *', {
	enable: true,
	key: 'importSanctionList',
	startTime: new Date(),
	// immediate: true
	// endTime: new Date(new Date().getTime() + 24 * 60 * 60 * 1000),
})*/
async importSanctionList() {
	console.log("Run importSanctionList");
}

private _parseXML(xml) : Promise<any> {
	return xml2js.parseStringPromise(xml, {
		ignoreAttrs: true,
		trim: true,
		explicitArray: false,
		normalizeTags: true
	});
}

@OnQueueActive()
onActive(job: Job) {
	console.log(
		`Processing job ${job.id} of type ${job.name} with data ${job.data}...`,
	);
}

@OnQueueEvent(BullQueueEvents.COMPLETED)
onCompleted(job: Job) {
	console.log(
		`Completed job ${job.id} of type ${job.name} with result ${job.returnvalue}`,
	);
}

}`

I need the importSanctionList function to run at midnight every day.

@fwoelffel
Copy link
Contributor

Hi @jphgardner02
You could try to add a repeatable job in your queue. See https://optimalbits.github.io/bull#repeatable

@fwoelffel fwoelffel added meta This is not directly related to the sources question Further information is requested labels Sep 18, 2019
@jphgardner02
Copy link
Author

jphgardner02 commented Sep 18, 2019

@fwoelffel Is there a way to add this to the @ Process Decorator, or would i have to add a repeatable job everytime nestjs starts?

@fwoelffel
Copy link
Contributor

I haven't tried this myself, but I guess you would have to add the repeatable job everytime NestJS starts. According to Bull's documentation, the library is smart enough not to add/process the same repeatable job multiple times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta This is not directly related to the sources question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants