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

my solution for stuck jobs in active and inactive state, but is it possible to make this run in every job process? without restart the server #1240

Open
hotaryuzaki opened this issue Apr 24, 2020 · 0 comments

Comments

@hotaryuzaki
Copy link

hotaryuzaki commented Apr 24, 2020

i don't know this is a good or a bad way, because i'm new in Kue.
i got to maintenance my company system, they used Kue when develop this.
and sadly this repo no longer maintained.

here is my solution, it works good for me.
but i cannot make this works as programatically when server is running. (we have to restart the server to clear all mess)

so my question is it possible to make this run in every job process?
maybe run as a function and we can call it when needed??

/***
	REMOVE ALL STUCK JOBS WHEN SAILS LIFT
	THEN RUN QUEUE PROCESS
***/
try {
	// GET SPECIFIC JOB BY JOB TYPE - CURRENTLY JUST FOR CHECKING STATUS
	kue.Job.rangeByType(jobType1, 'inactive', 0, 100, 'asc', function(err, jobs) {
		var ids = [];

	  jobs.forEach(function(job) {
	  	ids.push(job.id);
	  });

		console.log(jobType1, '=> STUCK JOBS INACTIVE TOTAL:', jobs.length, '=', ids);
	});

	kue.Job.rangeByType(jobType2, 'inactive', 0, 100, 'asc', function(err, jobs) {
		var ids = [];

	  jobs.forEach(function(job) {
	  	ids.push(job.id);
	  });

		console.log(jobType2, '=> STUCK JOBS INACTIVE TOTAL:', jobs.length, '=', ids);
	});

	kue.Job.rangeByType(jobType3, 'inactive', 0, 100, 'asc', function(err, jobs) {
		var ids = [];

	  jobs.forEach(function(job) {
	  	ids.push(job.id);
	  });

		console.log(jobType3, '=> STUCK JOBS INACTIVE TOTAL:', jobs.length, '=', ids);
	});


	/*########## KUE GET ALL ACTIVE JOBS ##########*/
	queue.active(function(err, ids) {
		console.log('QUEUE => JOBS ACTIVE STUCK IDS:', ids)

	  ids.forEach(function(id) {
	    kue.Job.get(id, function(err, job) {
	      job.inactive(); // SET ALL STUCK JOBS ACTIVE TO INACTIVE
	    });
	  });


		/*########## KUE GET ALL INACTIVE JOBS ##########*/
		queue.inactive(function(err, ids) {
			console.log('QUEUE => JOBS INACTIVE STUCK IDS:', ids)

		  ids.forEach(function(id) {
		  	kue.Job.get(id, function(err, job) {
		  		// REMOVE ALL STUCK JOBS
					job.remove(function(err){
				    if (err) throw err;
				    console.log('QUEUE =>', job.type, '=> JOB REMOVED #', job.id);
				  });
			  });
		  });

			queue.process(jobType1, function(job, done){
				try {
				     // process
				     done();
				} catch(e) {
					done(e);
				}
			});

			queue.process(jobType2, function(job, done){
				try {
				     // process
				     done();
				} catch(e) {
					done(e);
				}
			});

			queue.process(jobType3, function(job, done){
				try {
				     // process
				     done();
				} catch(e) {
					done(e);
				}
			});
		});
	});

} catch(e) {
	// statements
	console.log(e);
}```
@hotaryuzaki hotaryuzaki reopened this Apr 24, 2020
@hotaryuzaki hotaryuzaki changed the title my solution for stuck jobs in active and inactive state my solution for stuck jobs in active and inactive state, but is it possible to make this run in every job process? without restart the server Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant