1 00:00:00,150 --> 00:00:02,430 ‫Now let's look at Activity Tasks 2 00:00:02,430 --> 00:00:03,660 ‫in step function. 3 00:00:03,660 --> 00:00:05,730 ‫And the intent may be very similar 4 00:00:05,730 --> 00:00:08,610 ‫to what we have with the wait for task token pattern 5 00:00:08,610 --> 00:00:10,230 ‫that we saw just before, 6 00:00:10,230 --> 00:00:12,960 ‫but the way of achieving it is slightly different. 7 00:00:12,960 --> 00:00:16,260 ‫So here we have what's called activity workers 8 00:00:16,260 --> 00:00:19,440 ‫and they want to perform tasks from your step functions. 9 00:00:19,440 --> 00:00:21,900 ‫So these activity workers, they may be running 10 00:00:21,900 --> 00:00:25,410 ‫on EC2 instances, Lambda functions, mobile devices, 11 00:00:25,410 --> 00:00:26,550 ‫whatever you want, 12 00:00:26,550 --> 00:00:30,660 ‫and these activity workers are going to regularly pull 13 00:00:30,660 --> 00:00:33,900 ‫for your step function's workflow to find a task. 14 00:00:33,900 --> 00:00:36,000 ‫And they will use the GetActivityTask API. 15 00:00:37,830 --> 00:00:40,920 ‫And then if they get work back from step functions, 16 00:00:40,920 --> 00:00:43,140 ‫they will do the work, complete the work, 17 00:00:43,140 --> 00:00:46,680 ‫and then send a response with SendTaskSuccess 18 00:00:46,680 --> 00:00:50,070 ‫or SendTaskFailure, which is the same API call as before. 19 00:00:50,070 --> 00:00:52,470 ‫So here, the EC2 instance, for example, 20 00:00:52,470 --> 00:00:55,260 ‫which is my activity worker, is going to be pulling 21 00:00:55,260 --> 00:00:56,960 ‫for a task with a GetActivityTask, 22 00:00:57,813 --> 00:00:59,160 ‫then step function says yes, 23 00:00:59,160 --> 00:01:00,960 ‫there is something for you to do, actually. 24 00:01:00,960 --> 00:01:03,690 ‫So here is the input and here is the task token. 25 00:01:03,690 --> 00:01:06,660 ‫And then when the task is completed, we send back the output 26 00:01:06,660 --> 00:01:09,810 ‫and the task token with SendTaskSuccess. 27 00:01:09,810 --> 00:01:13,590 ‫So this may look very similar to what we have shown before, 28 00:01:13,590 --> 00:01:15,000 ‫but there is a difference in the activity. 29 00:01:15,000 --> 00:01:19,350 ‫In the Activity Task mechanism are EC2 instances 30 00:01:19,350 --> 00:01:21,900 ‫or applications, whatever, are pulling 31 00:01:21,900 --> 00:01:24,270 ‫from step functions for some work. 32 00:01:24,270 --> 00:01:27,150 ‫And the network is quite easy because, well, 33 00:01:27,150 --> 00:01:28,650 ‫the EC2 instance just needs to be able 34 00:01:28,650 --> 00:01:30,300 ‫to connect to step functions. 35 00:01:30,300 --> 00:01:32,310 ‫So here we have a pull mechanism 36 00:01:32,310 --> 00:01:35,760 ‫and most likely a simple network diagram. 37 00:01:35,760 --> 00:01:38,370 ‫When we were looking at the previous one , 38 00:01:38,370 --> 00:01:41,310 ‫where we sent the task with a callback externally, 39 00:01:41,310 --> 00:01:43,200 ‫what was going to happen is that step functions 40 00:01:43,200 --> 00:01:47,220 ‫was pushing an event out, for example, to an SQS queue, 41 00:01:47,220 --> 00:01:49,590 ‫and so there's a push mechanism. 42 00:01:49,590 --> 00:01:52,380 ‫And then again we need to have something that pulls 43 00:01:52,380 --> 00:01:55,590 ‫that work from outside and gets it back into step functions. 44 00:01:55,590 --> 00:01:58,470 ‫So this is quite a different way of working 45 00:01:58,470 --> 00:02:01,860 ‫because we have a pull-based mechanism for Activity Task 46 00:02:01,860 --> 00:02:05,190 ‫and a push-based mechanism for the callback pattern 47 00:02:05,190 --> 00:02:07,980 ‫with a wait for task token. 48 00:02:07,980 --> 00:02:10,380 ‫So now we understand the differences, 49 00:02:10,380 --> 00:02:14,010 ‫and in the case of an EC2 instance pulling from work 50 00:02:14,010 --> 00:02:16,050 ‫from step functions, it looks very similar 51 00:02:16,050 --> 00:02:17,700 ‫to what we have with queues 52 00:02:17,700 --> 00:02:19,650 ‫and so we have a few parameters. 53 00:02:19,650 --> 00:02:22,020 ‫First of all, there is the TimeoutSeconds, 54 00:02:22,020 --> 00:02:25,950 ‫which is how long a task that is in progress can wait 55 00:02:25,950 --> 00:02:28,320 ‫until it is considered a failure. 56 00:02:28,320 --> 00:02:30,120 ‫And that's the TimeoutSeconds. 57 00:02:30,120 --> 00:02:33,450 ‫And then there is also the heartbeat mechanism, 58 00:02:33,450 --> 00:02:36,390 ‫which is to say that as long as the EC2 instance, 59 00:02:36,390 --> 00:02:40,350 ‫the activity worker, is going to use the Send HeartBeat 60 00:02:40,350 --> 00:02:43,860 ‫API call, then we consider the task to be alive. 61 00:02:43,860 --> 00:02:47,250 ‫And there is a HeartBeatSeconds configuration that you set 62 00:02:47,250 --> 00:02:49,380 ‫on your step functions which defines 63 00:02:49,380 --> 00:02:53,580 ‫how long is the maximum time to wait for a heartbeat. 64 00:02:53,580 --> 00:02:55,920 ‫And so of course, if you set 10 seconds 65 00:02:55,920 --> 00:02:59,010 ‫for HeartBeatSeconds, it may be a good idea 66 00:02:59,010 --> 00:03:02,370 ‫to send a task heartbeat every five seconds 67 00:03:02,370 --> 00:03:05,580 ‫so that the task is alive often enough. 68 00:03:05,580 --> 00:03:09,240 ‫Now, if you configure a very long TimeoutSeconds 69 00:03:09,240 --> 00:03:11,370 ‫and you keep on sending a heartbeat, 70 00:03:11,370 --> 00:03:16,370 ‫then the actual Activity Task can wait up to one year. 71 00:03:16,440 --> 00:03:18,690 ‫Okay, so that's it for Activity Tasks. 72 00:03:18,690 --> 00:03:22,053 ‫I hope you liked it and I will see you in the next lecture.