A package like synced-cron


#1

Hi,

I need to update some documents in my collection in specific time and with specific id given by the client ; but it seems that I can’t do it with synced-cron.

Is there a package like percolate:synced-cron that can be called from the client-side and tacke id and time like arguments??


#2

Use later.js. Pretty easy library.


#3

@corvid, thank’s but it seems not taking arguments also; I need if it possible something that can be called from the client and take argument


#4

Can you shed a little more light on why you want something like this? Triggering scheduled activities from the client side sounds like a recipe for disaster. First of all you can’t guarantee your scheduling code stays active on the client side long enough to be run (for example, your users could shut their browser down before your scheduled task is run at a specific time). Also, driving scheduled tasks from the client side means you’re dependent on your users local clock. They could have their time set to anything, which could mess up the triggering schedule.


#5

@hwillson; Hi, I 'll explain you what I want exactly;

In my reac – meteor app ; the user

  • can do so many shooping lists he wants
  • can put a reminder for one list or for more
  • Each list has its own id ;

For this , I need to send the hour and the date set by the user in client side , and also the id of the list; and pass the all to a package like cron ( in server side ) ; so that when the time came , it(cron or other package) sent a reminder of each lists(id) to the user.

I hop that the idea is more clear now;


#6

Did you look at job-collection?

Also some potentially useful ideas discussed here: https://crater.io/posts/cE6hFfXXiGfT2FmBw/package-design-task-scheduling


#7

@hluz Thank’s for link


#8

To keep things simple, you could consider doing something like:

  • When a user adds a reminder on the client side, store the hour, date and list ID in a Reminders Collection (I’d recommend calling an addReminder Method that then updates the Reminders Collection).
  • On the server side setup a synched cron job that monitors the Reminders collection every few minutes. When it finds a reminder that needs to be fired (based on the reminder hour/date), you can then kick off whatever reminder processing you need to handle (by leveraging the stored list ID).

#9

@hwillson; Thank’s I like this concept;
How can Know if the cron is finished or no, is there some cron mothed that can do that ??


#10

@corvid can you explain how to use later.js in Meteor 1.3 ?


#11

If you’re using percolate:synced-cron it logs all job details in a Collection called cronHistory. You can get details like intendedAt, startedAt, finishedAt, etc. for any job from this Collection.


#12

@hwillson, wooow, it seems there is no example using that to remove job when it’s finished (when I search on google.)
have you an example using that, please? or how to remove job after the job being finished??


#13

You can remove any job using SyncedCron.remove('some job name'). You could have a cleanup job that queries the cronHistory Collection looking for jobs that have a finishedAt timestamp that’s older than the current timestamp, then remove those jobs by name.

You can also schedule jobs to only run once (non-reoccuring) by doing something like:

SyncedCron.add({
  name: 'Do something awesome, but only once!',
  schedule(parser) {
    return parser.recur().on(someDate).fullDate();
  },
  job() {
    // Do something ...
  },
});

#14

@hwillson That’s what I’m looking for, how to query the cronHistory Collection ??


#15

cronHistory is just a Mongo collection, so you can query it like you would any other Mongo Collection in Meteor:

...
const cronHistory = new Mongo.Collection('cronHistory');
...
const someJob = cronHistory.findOne();
console.log(someJob.finishedAt);
...

#16

@hwillson

this code break my app

const cronHistory = new Mongo.Collection('cronHistory');

it said that this collection exists,

Is there something wrong?


#17

Okay - in that case try using the cronHistory Collection directly from SyncedCron. So:

...
const cronHistory = SyncedCron._collection;
...
const someJob = cronHistory.findOne();
console.log(someJob.finishedAt);
...

#18

@hwillson prefect, Thank’s


#19

i am facing a strange behavior , so i was wondering do the Roles or the simple schema affect the synced-cron in a way ?
updating collections using synced-cron is functioning well only on some particular collections … any idea ?


#20

@mokaid sorry for late answer, to be honset I don’t if they affect it or no :frowning:

Sorry