{"_id":"588fd9bfbc2dbf0f00991001","parentDoc":null,"category":{"_id":"588f722bbcace50f0052b9e3","version":"588f722bbcace50f0052b9e1","project":"565f5fa26bafd40d0030a064","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-09T21:22:52.427Z","from_sync":false,"order":1,"slug":"user-guide","title":"Reference"},"__v":0,"user":"588f6dbe6bc3360f0068d2a1","version":{"_id":"588f722bbcace50f0052b9e1","project":"565f5fa26bafd40d0030a064","__v":1,"createdAt":"2017-01-30T17:04:43.410Z","releaseDate":"2017-01-30T17:04:43.410Z","categories":["588f722bbcace50f0052b9e2","588f722bbcace50f0052b9e3","588f722bbcace50f0052b9e4","588f722bbcace50f0052b9e5","588f722bbcace50f0052b9e6","588f722bbcace50f0052b9e7"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"5.3.0","version":"5.3.0"},"project":"565f5fa26bafd40d0030a064","updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-01-31T00:26:39.650Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":16,"body":"Jobs allow you to execute business logic at scheduled intervals. Creating the business logic is identical to creating a Proxy Endpoint with the exception that they are created under the Jobs tab under the API Dashboard instead of under Proxy endpoints. \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/787496f-job-name-list.png\",\n        \"job-name-list.png\",\n        1522,\n        360,\n        \"#f7f7f7\"\n      ]\n    }\n  ]\n}\n[/block]\nScheduling a job is configured under the Manage tab and does not export when exporting an API configuration. After entering a job schedule name, select the API and then the name of the job under that API (select the API before selecting the Job name). Only Job names and not Proxy endpoints are available in the Job list for the selected API.  \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/1e45686-schedule-job.png\",\n        \"schedule-job.png\",\n        1260,\n        491,\n        \"#f3f4f4\"\n      ]\n    }\n  ]\n}\n[/block]\nOnce the Job schedule record is created, edit the schedule of when the job is run. \n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/d48bc6b-edit-job-schedule.png\",\n        \"edit-job-schedule.png\",\n        899,\n        652,\n        \"#edeeee\"\n      ]\n    }\n  ]\n}\n[/block]\nThe Job schedule has the following properties:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"property\",\n    \"h-1\": \"type\",\n    \"h-2\": \"description\",\n    \"0-0\": \"Name (required)\",\n    \"0-1\": \"`string`\",\n    \"1-0\": \"API (required)\",\n    \"2-0\": \"Job (required)\",\n    \"3-0\": \"Once\",\n    \"4-0\": \"Time Zone (required)\",\n    \"5-0\": \"Minutes (required)\",\n    \"6-0\": \"Hour (required)\",\n    \"7-0\": \"Day of Month (required)\",\n    \"8-0\": \"Month (required)\",\n    \"9-0\": \"Day of Week (required)\",\n    \"10-0\": \"Parameters\",\n    \"10-1\": \"`object`\",\n    \"1-1\": \"`string`\",\n    \"2-1\": \"`string`\",\n    \"3-1\": \"`boolean`\",\n    \"4-1\": \"`string`\",\n    \"4-2\": \"Choose the time zone of when the job will run.  Note that if you choose PST and the job is scheduled to run at 10am, but your computer's clock is set to EST, when nanoscale.io lists the next time the job is run, it will display as 1pm.\",\n    \"5-1\": \"`number`\",\n    \"6-1\": \"`number`\",\n    \"7-1\": \"`number`\",\n    \"8-1\": \"`number`\",\n    \"9-1\": \"`number`\",\n    \"0-2\": \"Name of the Job schedule.\",\n    \"1-2\": \"Select the API where the job business logic is created.\",\n    \"2-2\": \"Select the job name to execute.\",\n    \"3-2\": \"When checked, the job will only run once.\",\n    \"5-2\": \"Enter 0-59 for the minute.\",\n    \"6-2\": \"Enter 0-23 for the hour.\",\n    \"7-2\": \"Enter 1-31 for the day of month.\",\n    \"8-2\": \"Enter 1-12 for the month.\",\n    \"9-2\": \"Enter 0-6 (Sunday – Saturday) for the day of the week.\",\n    \"10-2\": \"If your job is expecting parameters, enter the parameters to pass to the job.\"\n  },\n  \"cols\": 3,\n  \"rows\": 11\n}\n[/block]\n###Configure When the Job Runs\nThe `Minute`, `Hour`, `Day of Month`, `Month`, and `Day of Week` are numeric values which represent when the job will execute. nanoscale.io converts the values into a Cron job.  Here are some examples to understand how to configure your job to execute at specific intervals.\n\n  * If asterisks “*” are entered for all values, the job will run every minute, for every hour of every day of the year.  \n  * If 30 is entered in the Minute field (and \"*\" for all other fields), the job will run at 30 minutes past the hour every day of the year.  \n  * If 3 is entered in Day of Month (and \"*\" for all other fields), the job will run on the third day of the next month and then again on every third day of every month.  If you configure the job schedule on January 15, the first time the job will run is February 3. \n\nTo confirm the schedule settings go back to the Job schedules page and see when the next time the job will run under the Next column.  In the example below, the job is scheduled to run every 3rd day of the month.  If you come back to this page on February 4, 2017, the date in the Next column will be Mar 3, 2017, 12:00AM.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/c13af20-view-job-schedule.png\",\n        \"view-job-schedule.png\",\n        899,\n        314,\n        \"#f6f7f6\"\n      ]\n    }\n  ]\n}\n[/block]\nIf you need to execute the job multiple times during the hour, for example, at 30 and 45 minutes past the hour, then you must create two separate job schedules.  \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/a77088d-multiple-job-schedules.png\",\n        \"multiple-job-schedules.png\",\n        900,\n        312,\n        \"#f6f7f6\"\n      ]\n    }\n  ]\n}\n[/block]\n###Executing Jobs as a Proxy Endpoint\nJobs can also be executed as a Proxy endpoint. To do this, a Job Remote endpoint must be created. For help on creating a Job Remote endpoint, click [here](http://devhub.nanoscale.io/docs/remote-endpoints#job). \n\nConfigure your Proxy endpoint just as you would any endpoint selecting the Job Remote endpoint.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/519abb4-run-job-proxy-endpoint.png\",\n        \"run-job-proxy-endpoint.png\",\n        1373,\n        950,\n        \"#efefee\"\n      ]\n    }\n  ]\n}\n[/block]\nThe request to execute the job would look something like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"console.log(\\\"Triggering the Job\\\");\\nvar city = request.params.city;\\nvar country = request.params.country;\\n\\nvar parameters = {\\n  \\\"city\\\": city,\\n  \\\"country\\\": country\\n};\\njobRemoteEndPoint.request = new AP.Job.Request();\\njobRemoteEndPoint.request.run(\\\"FetchWeatherJob\\\", parameters);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"jobs","type":"basic","title":"Jobs"}
Jobs allow you to execute business logic at scheduled intervals. Creating the business logic is identical to creating a Proxy Endpoint with the exception that they are created under the Jobs tab under the API Dashboard instead of under Proxy endpoints. [block:image] { "images": [ { "image": [ "https://files.readme.io/787496f-job-name-list.png", "job-name-list.png", 1522, 360, "#f7f7f7" ] } ] } [/block] Scheduling a job is configured under the Manage tab and does not export when exporting an API configuration. After entering a job schedule name, select the API and then the name of the job under that API (select the API before selecting the Job name). Only Job names and not Proxy endpoints are available in the Job list for the selected API. [block:image] { "images": [ { "image": [ "https://files.readme.io/1e45686-schedule-job.png", "schedule-job.png", 1260, 491, "#f3f4f4" ] } ] } [/block] Once the Job schedule record is created, edit the schedule of when the job is run. [block:image] { "images": [ { "image": [ "https://files.readme.io/d48bc6b-edit-job-schedule.png", "edit-job-schedule.png", 899, 652, "#edeeee" ] } ] } [/block] The Job schedule has the following properties: [block:parameters] { "data": { "h-0": "property", "h-1": "type", "h-2": "description", "0-0": "Name (required)", "0-1": "`string`", "1-0": "API (required)", "2-0": "Job (required)", "3-0": "Once", "4-0": "Time Zone (required)", "5-0": "Minutes (required)", "6-0": "Hour (required)", "7-0": "Day of Month (required)", "8-0": "Month (required)", "9-0": "Day of Week (required)", "10-0": "Parameters", "10-1": "`object`", "1-1": "`string`", "2-1": "`string`", "3-1": "`boolean`", "4-1": "`string`", "4-2": "Choose the time zone of when the job will run. Note that if you choose PST and the job is scheduled to run at 10am, but your computer's clock is set to EST, when nanoscale.io lists the next time the job is run, it will display as 1pm.", "5-1": "`number`", "6-1": "`number`", "7-1": "`number`", "8-1": "`number`", "9-1": "`number`", "0-2": "Name of the Job schedule.", "1-2": "Select the API where the job business logic is created.", "2-2": "Select the job name to execute.", "3-2": "When checked, the job will only run once.", "5-2": "Enter 0-59 for the minute.", "6-2": "Enter 0-23 for the hour.", "7-2": "Enter 1-31 for the day of month.", "8-2": "Enter 1-12 for the month.", "9-2": "Enter 0-6 (Sunday – Saturday) for the day of the week.", "10-2": "If your job is expecting parameters, enter the parameters to pass to the job." }, "cols": 3, "rows": 11 } [/block] ###Configure When the Job Runs The `Minute`, `Hour`, `Day of Month`, `Month`, and `Day of Week` are numeric values which represent when the job will execute. nanoscale.io converts the values into a Cron job. Here are some examples to understand how to configure your job to execute at specific intervals. * If asterisks “*” are entered for all values, the job will run every minute, for every hour of every day of the year. * If 30 is entered in the Minute field (and "*" for all other fields), the job will run at 30 minutes past the hour every day of the year. * If 3 is entered in Day of Month (and "*" for all other fields), the job will run on the third day of the next month and then again on every third day of every month. If you configure the job schedule on January 15, the first time the job will run is February 3. To confirm the schedule settings go back to the Job schedules page and see when the next time the job will run under the Next column. In the example below, the job is scheduled to run every 3rd day of the month. If you come back to this page on February 4, 2017, the date in the Next column will be Mar 3, 2017, 12:00AM. [block:image] { "images": [ { "image": [ "https://files.readme.io/c13af20-view-job-schedule.png", "view-job-schedule.png", 899, 314, "#f6f7f6" ] } ] } [/block] If you need to execute the job multiple times during the hour, for example, at 30 and 45 minutes past the hour, then you must create two separate job schedules. [block:image] { "images": [ { "image": [ "https://files.readme.io/a77088d-multiple-job-schedules.png", "multiple-job-schedules.png", 900, 312, "#f6f7f6" ] } ] } [/block] ###Executing Jobs as a Proxy Endpoint Jobs can also be executed as a Proxy endpoint. To do this, a Job Remote endpoint must be created. For help on creating a Job Remote endpoint, click [here](http://devhub.nanoscale.io/docs/remote-endpoints#job). Configure your Proxy endpoint just as you would any endpoint selecting the Job Remote endpoint. [block:image] { "images": [ { "image": [ "https://files.readme.io/519abb4-run-job-proxy-endpoint.png", "run-job-proxy-endpoint.png", 1373, 950, "#efefee" ] } ] } [/block] The request to execute the job would look something like this: [block:code] { "codes": [ { "code": "console.log(\"Triggering the Job\");\nvar city = request.params.city;\nvar country = request.params.country;\n\nvar parameters = {\n \"city\": city,\n \"country\": country\n};\njobRemoteEndPoint.request = new AP.Job.Request();\njobRemoteEndPoint.request.run(\"FetchWeatherJob\", parameters);", "language": "javascript" } ] } [/block]