Suggest: Resources and times for a job

Optimize resources, schedule, and dispatch a job using the optimize/resource_suggestions endpoint and GraphQL

You can use Skedulo REST API and GraphQL endpoints to remotely optimize a job, assign it to a resource, and send them a notification.

The /planr/optimize/resource_suggestions endpoint returns a list of resources that are able to fulfil the requirements of the job at a scheduled time. Use GraphQL to assign and schedule the job based on the results of the Planr query, then use the /notify/dispatch REST endpoint to dispatch the job.

  1. Use the /optimize/resource_suggestions Planr REST API endpoint to get a list of suggested resources and times to schedule the job.

    {
      "jobId": "0014586b-3fa3-4f74-a5b1-a47f22a4b3a2",
      "resources": {
        "0005c30e-2b8e-4a02-a6e6-f59a73275330": [
          {
            "start": "2019-04-01T02:04:58Z",
            "end": "2019-04-02T02:04:58Z"
          }
        ],
        "00059f57-6b9a-4a3d-a724-5fbbcab4f800": [
          {
            "start": "2019-04-01T02:04:58Z",
            "end": "2019-04-02T02:04:58Z"
          }
        ]
      },
      "scheduleStart": "2019-04-01T02:04:58Z",
      "scheduleEnd": "2019-04-02T02:04:58Z",
      "schedulingOptions": {
        "jobTimeAsTimeConstraint": true,
        "preferJobTimeOverTimeConstraint": true,
        "respectSchedule": true,
        "ignoreTravelTimes": false,
        "ignoreTravelTimeFirstJob": false,
        "ignoreTravelTimeLastJob": false,
        "padding": 0,
        "snapUnit": 0
      }
    }
    

    This returns two available resources and the time they are able to start the job.

    {
     "result": {
       "0005c30e-2b8e-4a02-a6e6-f59a73275330": {
         "resourceId": "0005c30e-2b8e-4a02-a6e6-f59a73275330",
         "jobId": "0014586b-3fa3-4f74-a5b1-a47f22a4b3a2",
         "score": {
           "hard": 0,
           "medium": 0,
           "soft": 0
         },
         "start": "2019-04-01T02:04:58.000Z",
         "duration": 60,
         "travelTime": 0,
         "currentCapacityInSeconds": 86400,
         "newCapacityInSeconds": 82800,
         "travel": {
           "distanceFromHome": null,
           "durationFromHome": null
         }
       },
       "00059f57-6b9a-4a3d-a724-5fbbcab4f800": {
         "resourceId": "00059f57-6b9a-4a3d-a724-5fbbcab4f800",
         "jobId": "0014586b-3fa3-4f74-a5b1-a47f22a4b3a2",
         "score": {
           "hard": 0,
           "medium": 0,
           "soft": 0
         },
         "start": "2019-04-01T03:50:00.000Z",
         "duration": 60,
         "travelTime": 0,
         "currentCapacityInSeconds": 82800,
         "newCapacityInSeconds": 79200,
         "travel": {
           "distanceFromHome": 0,
           "durationFromHome": 0
         }
       }
     }
    }
    
  2. To accept and implement this result, use a GraphQL mutation to update and schedule the job, then create a JobAllocation to assign the resource to the job. You can perform both of these actions in the same transaction by defining an alias for each action to disambiguate the results:

  • updateJobs: schedules the Start and End times for the job.

  • insertJobAllocations: assigns the job to a resource.

    mutation saveSuggestResult{
        schema {
          updateJobs(input: {
            UID: "0014a76c-dfa1-4e78-87b3-635b7d7f4897"
            Start: "2019-04-03T23:00:00.000Z"
            End: "2019-04-04T00:30:00.000Z"
            Duration: 90
          })
          insertJobAllocations(input: {
            JobId: "0014a76c-dfa1-4e78-87b3-635b7d7f4897"
            ResourceId: "0005c30e-2b8e-4a02-a6e6-f59a73275330"
          })
        }
      } 
    

    The successful response includes the UID for each of the objects that have been modified in each step. In this example, it is the job (scheduled) and the resource (allocated) that have been modified.

    {
      "data": {
        "schema": {
          "updateJobs": "0014a76c-dfa1-4e78-87b3-635b7d7f4897",
          "insertJobAllocations": "0018422b-b85e-469e-a2e7-e171bf625e1c"
        }
      }
    }
    

Repeat this step for each job query result that you want to implement.

  1. The jobs are now ready to be dispatched to the assigned resources. Use the dispatch REST API endpoints, available via the Skedulo API, to dispatch the jobs and notify the resources:

    For example, to dispatch the job described in the previous steps to the assigned resource, make a POST call to the notifications/dispatch endpoint with the following payload:

    {
      "jobId": "0014a76c-dfa1-4e78-87b3-635b7d7f4897",
      "resourceIds": [
        "0005c30e-2b8e-4a02-a6e6-f59a73275330"
      ]
    }
    

    This sends a message to the resource using their notification preference and sets the job to Dispatched.

    A successful response confirms that the resource was notified of the job by either sms or push notification:

    {
      "result": {
        "jobId": "0014a76c-dfa1-4e78-87b3-635b7d7f4897",
        "results": [
          {
            "resourceId": "0005c30e-2b8e-4a02-a6e6-f59a73275330",
            "protocol": "sms",
            "error": null
          }
        ]
      }
    }