Comments (9)
Hi @dr-dimitru
Ah, super, that's exactly what I need!
Apparently I did not try the obvious one :D
Those snippets might also be nice for the documentation..
Thanks a lot for your help and the great package!
from josk.
Hello @MaxTwentythree ,
Updates would work behind the scenes. Just create a new task with same task id "uid", and it would get updated.
Firstly I wonder why it's necessary to append "setTimeout" / "setInterval" to the task uid?
No, package does it for you. The reason — be able to create Interval and Timeout tasks with same uid. To be honest — I don't see in the docs suggesting uid
to be in the form of ${taskId}setTimeout
Secondly removing a task and recreating it within the same Meteor method doesn't work.
I'd like to see code snippet where yu remove the task and that doesn't work.
(I think it's what you mean with "Should be called in a separate event loop").
Here's example:
const timer = job.setTimeout(func, 34789, 'unique-taskid');
someAsyncCall(() => {
job.clearTimeout(timer);
});
Another example:
const timer = job.setTimeout(func, 34789, 'unique-taskid');
process.nextTick(() => {
job.clearTimeout(timer);
});
Is there a proposed solution to achieving this?
What was your original question? Regarding updating existing task:
// CREATE NEW TASK
const timer = job.setTimeout(func, 34789, 'unique-taskid');
// UPDATE EXISTING TASK
const timer = job.setTimeout(otherFunc, 512, 'unique-taskid'); // <-- same 'unique-taskid'
from josk.
@MaxTwentythree I'm glad that was solved so quickly 😅
Thank you for documentation suggestion, let's keep it open until docs is updated
from josk.
Hi @dr-dimitru,
I now tried the update functionality but it doesn't seem to work :( .. maybe I did something wrong
Here's my method
function addTaskMethod(nodeId: string, endDate: Date) {
check(nodeId, String);
check(endDate, Date);
const now = new Date();
const diff = endDate.getTime() - now.getTime();
const db = Meteor.users.rawDatabase();
const job = new JoSk({db});
const taskId = `task ${nodeId}`;
const bound = Meteor.bindEnvironment((callback) => {
callback();
});
const task = function finishFeedbackPhaseTask(ready) {
bound(() => {
Meteor.call(someMethod, nodeId, () => {
ready();
});
});
};
job.setTimeout(task, diff, taskId);
}
When I call this method twice with a different enddate (but the same nodeId, which means same taskId) the task should update its executeAt prop, right?
from josk.
- Yes,
delay
andexecuteAt
properties should get updated - You should initiate
JoSk
only once, moveconst job = new JoSk({db});
out of theaddTaskMethod
function to global scope. Ideally you should initiate it in its own file andexport { job }
, thenimport
where used
Let me know if it helps
from josk.
Ah, I see, 2) makes a lot of sense ;)
I fixed this and initiate JoSk now only once.
But it didn't fix the update unfortunatelly.
I also tried the josk onError callback, but I don't get errors for the not updated tasks there..
It's not a big deal as I have a clearJob method anyways, which I now run before creating new tasks and it works like this.
Still curious why it doesn't work without it though..
from josk.
@MaxTwentythree will add it to our test suit, let's see if we can replicate it. Let's keep it open for now, thank you for reporting
from josk.
Thanks a lot @dr-dimitru !
from josk.
@MaxTwentythree it's been a while, no changes to the codebase were necessary. Please, see override
tests. The main difference between this and your examples, — .find()
called in the separate event-loop from creating and updating tsk
Lines 184 to 206 in 464a7ad
Feel free to reopen it in case if the issue is still persists on your end.
from josk.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from josk.