question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using classes to define jobs?

See original GitHub issue

I would like to know if it is possible to create a job as a class. For instance, would something like this be possible?

class SendNotificationMails extends someBaseJobClass {
  constructor() {
    this.attach("notification-mails", /*... other settings */)
  }
  async run() {
    // Execute job...
  }
}

It would make organizing a lot of background jobs much easier to write everything in classes and just have them register at an initial script.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
evantahlercommented, Apr 13, 2020

If you are looking for another example of a wrapping method, here’s how Actionhero takes it’s Task classes and structures them into the node-resque methods https://github.com/actionhero/actionhero/blob/3f9d936000d44afffd8798f1c3f5a3cb872390d2/src/initializers/tasks.ts#L62-L134

1reaction
glensccommented, Mar 31, 2020

I ended up creating this wrapper:

/**
 *
 * Wrapper to overcome issue that perform is called with wrong this context.
 *
 * @author Elan Ruusamäe <glen@pld-linux.org>
 *
 * https://github.com/actionhero/node-resque/issues/270
 */
class JobWrapper {
  static wrap(proxy: any) {
    return {
      perform: async (...args: []) => {
        return await proxy.perform.apply(proxy, args);
      }
    };
  }
}


  const jobs = {
    test: JobWrapper.wrap(new Job()),
  };
Read more comments on GitHub >

github_iconTop Results From Across the Web

Job Class Definition | Law Insider
Job Class refers to a group of jobs specified in Schedule "A" whose common characteristic is a specific point range and corresponding standard...
Read more >
Controlling the use of job names and job classes - IBM
Controlling the use of job names and job classes. You can use profiles in the JESJOBS class to control which job names and...
Read more >
Classes in Python: Definition and Examples (Plus Objects)
In Python, you use classes as schematics that define an object within the program's code, representing a group of data and functions.
Read more >
Working Class Explained: Definition, Compensation, Job ...
While "working class" is typically associated with manual labor and limited education, blue collar workers are vital to every economy.
Read more >
Specify Job Classes and Number of Initiators - TechDocs
For some job types, you can also specify a job class in a job definition. To find out which verbs and subverbs you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found