Last active
August 29, 2015 14:02
-
-
Save TheRyanHickman/9ec57d3f743562eb1528 to your computer and use it in GitHub Desktop.
Schedule a background job via cloud code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Parse Background Jobs via Rest API Scheduler Cloud Module | |
* @name Ryan Hickman | |
* | |
* Cloud Module for scheduling parse background jobs via rest api as a message queue | |
* | |
* To use this Cloud Module in Cloud Code, start by requiring | |
* the <code>mailgun</code> module and initializing it using your | |
* Mailgun domain name and api key. | |
* | |
* <pre>var BG = require('cloud/parseBGJobs-v1-1.0.js'); | |
* BG.initialize('',''); | |
* </pre> | |
* | |
*/ | |
(function() { | |
var _apiUrl = 'https://api.parse.com/1/jobs/'; | |
var _appID = ''; | |
var _masterKey = ''; | |
function wrappedHttpRequest(url, params, authenticateRequest) { | |
authenticateRequest = authenticateRequest || false; | |
return Parse.Cloud.httpRequest({ | |
url: url, | |
params: params, | |
method: 'POST', | |
body: { | |
request: params, | |
}, | |
headers:{ | |
'Content-Type': 'application/json', | |
'X-Parse-Application-Id': _appID, | |
'X-Parse-Master-Key': _masterKey | |
}, | |
success: function(httpResponse) { | |
console.log(httpResponse.text); | |
}, | |
error: function(httpResponse) { | |
console.log('Request failed with response code ' + httpResponse.status); | |
} | |
}); | |
} | |
module.exports = { | |
initialize: function(appID, masterKey) { | |
_appID = appID; | |
_masterKey = masterKey; | |
}, | |
scheduleJob: function(params) { | |
return wrappedHttpRequest(_apiUrl + params.job, params); | |
}, | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment