Skip to content

Support job on cloudcode #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

shoe116
Copy link

@shoe116 shoe116 commented Feb 13, 2016

Parse.com supported the cloud code as cron or job scheduler but parse-servier does not implement this feather.
https://parse.com/docs/server/guide#migrating

This patch makes parse-server support cron job.

If you has this job on cloud code

Parse.Cloud.define('hello', function(req, res) {
  res.success('Hello world!');
});

write

var CloudCode = require("../lib/CloudCode");
var cloud = new CloudCode(yourTimezone);
cloud.putJob("hello", null);
cloud.addCron("hello", "1 * * * *");
cloud.start();

on parse-server.

@gfosco
Copy link
Contributor

gfosco commented Feb 16, 2016

This is pretty cool, but a few requests:

Support the original definition signature of a cloud job: Parse.Cloud.job('jobName', function(request, status) {}); This would happen in src/index.js -> addParseCloud like how .define is implemented.

Maybe the scheduler/start stuff could be simplified and added under Parse.Cloud as well. It would be nice if they could just call 1 method, like Parse.Cloud.runJob('jobName', {params}, {options});, without having to start something. Options could include once:true or minutes:2 or cron:"1 * * * *", etc..

Thoughts?

@flovilmart
Copy link
Contributor

@gfosco let's wait for the multiple apps support to cook that in as the whole thing will need a revamp anyway.

@flovilmart
Copy link
Contributor

@shoe116 also we need to take into account the different environments. For heroku that's gonna be a worker, GAE has it's cron API too, I believe AWS beanstalk has a worker class too.

@facebook-github-bot
Copy link

@shoe116 updated the pull request.

@shoe116
Copy link
Author

shoe116 commented Feb 22, 2016

@gfosco Thank you for some good advice and sorry for late reply. OK, I will try adding new patch for this pull request.

@flovilmart GAE support is very useful, but it should be new issue and patch I think.

@flovilmart
Copy link
Contributor

@shoe116 What i mean by that, is that depending where you deploy you may not have a cron that work properly. So to avoid a full rewrite when a new 'adapter/provider' is implemented, we may want to abstract that right away.

@facebook-github-bot
Copy link

@shoe116 updated the pull request.

@taufiq-husain
Copy link

Which file would I put this code in:

var CloudCode = require("../lib/CloudCode");
var cloud = new CloudCode(yourTimezone);
cloud.putJob("hello", null);
cloud.addCron("hello", "1 * * * *");
cloud.start();

Is it the index.js file or main.js file? Is it something new I have to create? I'm using a heroku server in case you wanted to know: #668

success: (message) => {console.log(message)},
error: (message) => {console.error(message)}
}
this.jobs[name] = function(){Parse.Cloud.Functions[name](req, res);};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't work with the new architecture

@flovilmart
Copy link
Contributor

@shoe116 I believe it should be overhauled for now as the Parse.Cloud.Functions don't exist anymore. WE store everything through the triggers.js architecture.

What I suggest to move forward:

in src/triggers.js

  • add a Jobs, alongside Triggers and Functions
  • adds the Job registration method there too.

Add a job endpoint: https://www.parse.com/docs/rest/guide#cloud-code-background-jobs
Also an endpoint to create, update, delete jobs, not unlike the Parse.Hooks.js, it could be Parse.Jobs.js

That will make it easy to configure the jobs externally, from any client that has a masterKey.

You should log the job results, runs etc... into a _Jobs raw data store, this way we'll have the jobs history.

@shoe116
Copy link
Author

shoe116 commented Feb 28, 2016

@flovilmart Ok, I'll try to overhauled for my implementing. Thank you for your kind review.

@shoe116 shoe116 closed this Feb 28, 2016
@shoe116 shoe116 deleted the support_cron branch February 28, 2016 06:42
@tanmays
Copy link

tanmays commented Mar 3, 2016

@shoe116 @flovilmart is this still being worked upon? Jobs seems like the only major feature left now.

@gimdongwoo
Copy link

@sprabs
Copy link

sprabs commented Aug 20, 2016

@gimdongwoo @shoe116 @flovilmart This seems really useful. Has anyone rolled in a (background) jobs-related change into master?

@flovilmart
Copy link
Contributor

I don't see real benefits in including them into parse-server, and they are a pain to scale as soon as you have multiple instances.

Also note that there are plenty of solutions available out there to run scheduled jobs. And cloud functions expose a nice http URL to the outside world.

@gimdongwoo
Copy link

gimdongwoo commented Aug 21, 2016

@sprabs It need to big codes.
First of all, it needs job manage code for multi instance.
And, it needs job status managing(error, timeout, etc) and manage UI for job (add, delete, start, stop, etc).
This would undermine the simplicity of parse-server.

@flovilmart
Copy link
Contributor

What we can do is create a /job/:jobName alias, protected by a job key or the webhooks key. So they're not accessible as functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants