Giter VIP home page Giter VIP logo

veliovgroup / josk Goto Github PK

View Code? Open in Web Editor NEW
35.0 3.0 4.0 2.86 MB

Node.js setInterval and CRON tasks scheduler and manager for horizontally scaled multi-server applications

Home Page: https://www.npmjs.com/package/josk

License: BSD 3-Clause "New" or "Revised" License

JavaScript 100.00%
cron cluster scheduler scheduled-jobs jobs task tasks npm npm-package nodejs node-js horizontal-scaling mongodb redis task-manager task-scheduler

josk's Issues

TypeScript support

I have a suggestion:

The finial bit before I can use this library is missing the type declaration file.
The JSDoc is very clear in usage, but TypeScript doesn't pick that up.

why update before delete in __clear? how about just delete?

I have a question:

  1. why update before delete in __clear?
  __clear(uid) {
    this.collection.updateOne({
      uid: uid
    }, {
      $unset: {
        executeAt: '',
        inProgress: ''
      }
    }, (error) => {
      if (error && this.onError) {
        this.onError('[__clear] [updateOne] [error]', {
          description: 'Error in a callback of .updateOne() method of .__clear()',
          error: error,
          uid: uid
        });
      }

      this.collection.deleteOne({
        uid: uid
      }, mongoErrorHandler);
    });

    if (this.tasks && this.tasks[uid]) {
      delete this.tasks[uid];
    }
    return true;
  }
  1. how about just delete in __clear?
 __clear(uid) {
  try {
      this.collection.deleteOne({
        uid: uid
      });
  } catch(error) {
      if (error && this.onError) {
        this.onError('[__clear] [updateOne] [error]', {
          description: 'Error in a callback of .updateOne() method of .__clear()',
          error: error,
          uid: uid
        });
      }
  } finally{
    if (this.tasks && this.tasks[uid]) {
      delete this.tasks[uid];
    }
    return true;
  }
}

Update Tasks

Hi,

I'd like to update a task that already exists.
As this doesn't seem to be possible, my current workaround is to remove a task if it already exists and recreate it with the new values.

Firstly I wonder why it's necessary to append "setTimeout" / "setInterval" to the task uid?
Wouldn't it be better to be able to access a task with the uid it was actually created with?
Alternatively it would be nice to maybe have something like an exposed generateUid method so that I don't have to append setTimeout manually (for the case this logic might change later)..

Secondly removing a task and recreating it within the same Meteor method doesn't work.
(I think it's what you mean with "Should be called in a separate event loop").
I guess I could trigger the same Meteor method after deleting the task, but I'm not sure if this would even work and it feels kinda error-prone..

It does work if I do it manually, but I'm pretty sure that's bad practice:

const existingJob = job.collection.findOne({uid: `${taskId}setTimeout`});
if (existingJob) job.collection.remove({uid: `${taskId}setTimeout`});
...
job.setTimeout(task, diff, taskId)

Is there a proposed solution to achieving this?

Is there a way for getting logged-in user within the scheduled task?

I launch the task within the onLogin handler.
The task logic depends from logged in user.
Is there some way for getting logged-in user within the task?

I have tried do:

Meteor.userId()

and got error

Exception in callback of async function: Error: Meteor.userId can only be invoked in method calls or publications.

Is there some way getting logged in user?

If noway I see the following approach: to set a flag for the user in the Users collection before scheduling the task
Meteor.users.update({_id: loggedInUser._id}, {$set: {updateMeInTask: true}})

and drop this flag within the task?

Or may be is possible to pass a text value to the task?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.