Comments (14)
You could do something like:
if (!JobsInternal.Utilities.collection.findOne({name: name})) {
Jobs.run(JOB_ID, null, RUN_CONFIG);
}
FYI - as @gary-menzel mentioned - there is a v3 on the way which will feature this.replicate
so that each instance of the job has its own document. More info in CHANGES.md
https://github.com/msavin/SteveJobs...meteor.schedule.background.tasks.jobs.queue/tree/v3
from stevejobs.
That seems reasonable. Is V3 close to stable?
from stevejobs.
Oh I think another confounding factor is that this is a repeating job, so I do not end with this.success()
, I end with this.reschedule(...)
.
export function registerJob({
name,
run,
}: {
name: string;
run: (args: RunArguments) => Promise<void>;
}) {
console.info(`Registering ${name} job.`);
Jobs.register({
[name](args: RunArguments) {
/* Forward context/params to 'run' method - execute in a fiber-aware await to
allow regular async syntax in provided function */
MeteorPromise.await(run.apply(this, args));
},
});
}
const RUN_CONFIG: RunConfig = {
in: {
minutes: 5,
},
};
export const JOB_ID = 'job1';
async function runFunction(_args?: RunArguments) {
const self: JobInstance = this;
// ... do a bunch of stuff
// Run the job again, so it keeps looping.
self.reschedule(RUN_CONFIG);
}
registerJob({ name: JOB_ID, run: runFunction });
console.info(`Running ${JOB_ID} job.`);
Jobs.run(JOB_ID, null, RUN_CONFIG);
And the result is many entries in the job_data
collection, all with the pending
state.
from stevejobs.
#29 may also be related - I believe there is a V3 being planned that will readdress how rescheduling works.
from stevejobs.
This is working as it should. The problem is, the server is executing Jobs.run(JOB_ID, null, RUN_CONFIG)
every time it starts up. You only need to run it once to "jumpstart" it.
from stevejobs.
Oh that's interesting. Is there a way to check if that "jumpstart" has already been done? Allows me to ensure that the job is started as the code slides through different environments (and eventually to production).
from stevejobs.
And what's the easiest way to install V3?
from stevejobs.
I just pushed it - so run meteor update
and you'll have it. Let me know how it goes. :)
from stevejobs.
Perfect!
from stevejobs.
Awesome thats great! Thanks for the speedy response and the support.
from stevejobs.
If you are curious, this is what I came up with to wrap it into a cron job.
My business logic lives in an async
function the returns SUCCESS
or RETRY
and the wrappers in ^ do the work of rescheduling or replicating depending on the result. Also cancels the pending version on creation so the job can be updated with new code changes safely.
And I just call runRepeatingJob({ name: "jobName", job: myCoolFunction, args, repeatMinutes: 5 })
and the wrapper handles the rest. myCoolFunction
does not need to know anything about the implementation.
from stevejobs.
@jmoseley thanks for sharing and glad you got it working. Unfortunately, I'm not up on the latest es6 practicers, but once I am I will be sure to take a look :)
from stevejobs.
Ah ya it's typescript, so might be hard to grok up front, but hopefully it helps someone else get started.
from stevejobs.
@jmoseley Although I don't use TS, I found it useful. I have been using Promise a fair bit but somehow missed that there is a Meteor version available as a package. It looks like it makes working withMeteor.bindEnvironment
much more seamless. Thanks for the link.
from stevejobs.
Related Issues (20)
- List of available jobs to be run HOT 5
- Self is not defined error in 4.2.0 HOT 1
- Jobs Stuck Pending on Galaxy HOT 3
- server/imports/utilities/collection/index.js --> Cannot read property 'parent' of null HOT 4
- Prevent queue from stopping after failure HOT 8
- How to resume pending jobs when the server is restarted? HOT 1
- Missing index?
- Meteor 3.0 support (Fibers-free)
- Jobs.find not part of Atmosphere package HOT 4
- So what is the date format that's valid HOT 1
- Collection hooks HOT 1
- Version 3 causing rendering issue on instagram browser on iPhone HOT 2
- Possible to convert this to a pure Node.js package removing Meteor? HOT 3
- jobs are not run consecutively HOT 2
- Jobs: Unable to execute job - queue is busy: HOT 6
- V3.1.1 - Job runner stopped, jobs are not running anymore HOT 13
- Jobs: Unable to execute job - queue is busy, randomly appearing. HOT 2
- async / await Failure HOT 7
- Know if a queue is still processed HOT 2
- work with meteor 2.3 ? HOT 1
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 stevejobs.