The program/worker that gets uploaded must understand a few things:
- The job data can be retrieved from disk (or api?) by TODO..This data will be in json format and can be used in any fashion necessary (the sw gem for example uses it to set variables on the worker object).
- The ENV variable ['SW_REMOTE'] can be used to check if running locally or remote
Worker Code Implementation
This section will explain how to develop client code to upload to this endpoint. The examples are in ruby, but would apply to any language.
Let's start with an extremely simple example, let's say all I wanted to run was this:
That would be in a file called hello.rb .
Now let's get that running on SimpleWorker, so next I need to package it up.
Packaging Code
Code must be submitted as a zip file containing all of the necessary files to execute.
# this method will create a zip file given an array of file names.
def package_code(files)
fname = "package.zip"
File.delete(fname2) if File.exist?(fname)
Zip::ZipFile.open(fname, 'w') do |f|
files.each do |file|
f.add(file, file)
end
end
fname
end
zip_file = package_code(['hello.rb'])
So now I have to upload it to SimpleWorker
Uploading CodeTODO: example posting the zip file in a multipart post to this endpoint
After it's uploaded, I can now use it in queue and schedule commands. [TODO: link to queue/schedule]
Parameters
Required:
- name: referenceable name for your worker.
- file: zip file containing code to execute
- file_name: file name to execute
- runtime: language/runtime to execute your worker with.
- Currently accepts: ruby, python, javascript.
Optional:
Request
POST /2/projects/4e71843298ea9b6b9f000004/workers?oauth=jTxYQDmMx5ZtVeZBT8jVx6oJDLw HTTP/1.1
Response - Upload worker code, should include language and which file to execute, etc.
User-Agent: Ruby Content-Length: 13443 Accept: application/json Accept-Encoding: gzip, deflate Content-Type: multipart/form-data; boundary=775178
--775178 Content-Disposition: form-data; name="data"
{"name":"hello","standalone":true,"runtime":"python","file_name":"./hello.py","version":2,"timestamp":"2011-09-29T01:40:39Z","oauth":"jTxYQDmMx5ZtVeZBT8jVx6oJDLw"} --775178 Content-Disposition: form-data; name="file"; filename="package.zip" Content-Type: application/zip
=? --775178--
|