lykmapipo / kue-scheduler

A job scheduler utility for kue, backed by redis and built for node.js
246 stars 47 forks source link

Using Scheduler in POST with json API #93

Closed adampatarino closed 7 years ago

adampatarino commented 7 years ago

I'm building a custom UI for Kue and Kue-scheduler where users can submit their own jobs. I didn't see documentation on how to programmatically schedule jobs based on Kue's JSON API. Looking in Redis, I noticed that scheduler adds some fields to each job:

{
  "type": "email",
  "data": {
    "name": "Example Email",
    // Added Fields
    "unique": "email",
    "schedule": "RECCUR",
    "expiryKey": "q: scheduler: email",
    "dataKey": "q: scheduler: data: email"
  },
  "priority": 0,
  "progress": 0,
  "attempts": {
    "made": 0,
    "remaining": 3,
    "max": 3
  },
  // Added Field
  "reccurInterval": "1hour"
}

When creating a post object, what fields do I need to ensure are included? My guess is data.unique, and reccurInterval? Will Kue-scheduler know to make the rest of those fields? If not, how are expiryKey and dataKey generated? Or do you have a different recommendation on using the Kue Api with kue-scheduler?

lykmapipo commented 7 years ago

@adampatarino

  1. I didn't see documentation on how to programmatically schedule jobs based on Kue's JSON API kue-scheduler use kue for its internal and everything depends on kue except for every job which mix both redis key expiry events and kue job processing. If you want to schedule i will suggest to have a custom endpoints to which you will kick your jobs based on kue-scheduler.

  2. When creating a post object, what fields do I need to ensure are included? All kue required job attributes must be provided. So in your custom endpoint you will build the job and use kue-scheduler to schedule a job as described on usage.

  3. Will Kue-scheduler know to make the rest of those fields? Yes. Once have a job instance and pass to kue-scheduler scheduling API the rest will happen if things work as expected.

  4. Or do you have a different recommendation on using the Kue Api with kue-scheduler? Sincerely, I have been using kue-scheduler in all projects since its inception i.e for sending push notification, SMS, E-mail & any work that fit to run on independent process or background. I don't have a clean & concrete UI so far but I had a plan to improve on kue ui and kue json api to support kue-scheduler.

Hope it helps.

adampatarino commented 7 years ago

Thanks @lykmapipo

Ok, that makes sense. I can just make my own middleware API that programmatically creates the jobs, etc. Thanks for the advice!