Skip to content

Instantly share code, notes, and snippets.

@bleach
Created November 23, 2016 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bleach/25fb546421f826a48eb1230f33eacc69 to your computer and use it in GitHub Desktop.
Save bleach/25fb546421f826a48eb1230f33eacc69 to your computer and use it in GitHub Desktop.

What

There's no official CLI release with a UI that supports tasks yet, so I thought I'd confirm that they work.

Find out what my app guid is:

$ cf app --guid myapp
fc2d7a58-343f-47d2-bc24-0d611af11aa6

Submit a task:

$ cf curl -X POST /v3/apps/fc2d7a58-343f-47d2-bc24-0d611af11aa6/tasks -d '{ "name": "curl a URL", "command": "curl http://www.gdb.me/thisismetesting" }
'
{
   "guid": "648fc07e-06bd-477a-ae31-dec685fa7526",
   "sequence_id": 2,
   "name": "curl a URL",
   "command": "curl http://www.gdb.me/thisismetesting",
   "state": "RUNNING",
   "memory_in_mb": 1024,
   "result": {
      "failure_reason": null
   },
   "created_at": "2016-11-23T16:12:32Z",
   "updated_at": "2016-11-23T16:12:32Z",
   "droplet_guid": "1979585e-1936-4844-83d6-60dc60b2422a",
   "links": {
      "self": {
         "href": "https://api.cloud.service.gov.uk/v3/tasks/648fc07e-06bd-477a-ae31-dec685fa7526"
      },
      "app": {
         "href": "https://api.cloud.service.gov.uk/v3/apps/fc2d7a58-343f-47d2-bc24-0d611af11aa6"
      },
      "droplet": {
         "href": "https://api.cloud.service.gov.uk/v3/droplets/1979585e-1936-4844-83d6-60dc60b2422a"
      }
   }
}

Verifying it happened by checking the access logs of the server:

www.gdb.me:80 52.208.24.161 - - [23/Nov/2016:16:12:33 +0000] "GET /thisismetesting HTTP/1.1" 404 473 "-" "curl/7.35.0"

Verifying that CF thinks it happened (it's the second task):

$ cf curl /v3/tasks?app_guids=fc2d7a58-343f-47d2-bc24-0d611af11aa6
{
   "pagination": {
      "total_results": 2,
      "total_pages": 1,
      "first": {
         "href": "https://api.cloud.service.gov.uk/v3/tasks?app_guids=fc2d7a58-343f-47d2-bc24-0d611af11aa6&page=1&per_page=50"
      },
      "last": {
         "href": "https://api.cloud.service.gov.uk/v3/tasks?app_guids=fc2d7a58-343f-47d2-bc24-0d611af11aa6&page=1&per_page=50"
      },
      "next": null,
      "previous": null
   },
   "resources": [
      {
         "guid": "ccb1087c-eaee-4100-a4a0-097f71b04ba3",
         "sequence_id": 1,
         "name": "my first task",
         "state": "SUCCEEDED",
         "memory_in_mb": 1024,
         "result": {
            "failure_reason": null
         },
         "created_at": "2016-11-23T16:11:17Z",
         "updated_at": "2016-11-23T16:11:19Z",
         "droplet_guid": "1979585e-1936-4844-83d6-60dc60b2422a",
         "links": {
            "self": {
               "href": "https://api.cloud.service.gov.uk/v3/tasks/ccb1087c-eaee-4100-a4a0-097f71b04ba3"
            },
            "app": {
               "href": "https://api.cloud.service.gov.uk/v3/apps/fc2d7a58-343f-47d2-bc24-0d611af11aa6"
            },
            "droplet": {
               "href": "https://api.cloud.service.gov.uk/v3/droplets/1979585e-1936-4844-83d6-60dc60b2422a"
            }
         }
      },
      {
         "guid": "648fc07e-06bd-477a-ae31-dec685fa7526",
         "sequence_id": 2,
         "name": "curl a URL",
         "state": "SUCCEEDED",
         "memory_in_mb": 1024,
         "result": {
            "failure_reason": null
         },
         "created_at": "2016-11-23T16:12:32Z",
         "updated_at": "2016-11-23T16:12:33Z",
         "droplet_guid": "1979585e-1936-4844-83d6-60dc60b2422a",
         "links": {
            "self": {
               "href": "https://api.cloud.service.gov.uk/v3/tasks/648fc07e-06bd-477a-ae31-dec685fa7526"
            },
            "app": {
               "href": "https://api.cloud.service.gov.uk/v3/apps/fc2d7a58-343f-47d2-bc24-0d611af11aa6"
            },
            "droplet": {
               "href": "https://api.cloud.service.gov.uk/v3/droplets/1979585e-1936-4844-83d6-60dc60b2422a"
            }
         }
      }
   ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment