Return to Video

Set Up a Cron Job - Developing Scalable Apps with Java

  • 0:00 - 0:03
    So remember that set announcement servelet that you created
  • 0:03 - 0:06
    earlier? Now you're going to set up cron job
  • 0:06 - 0:08
    to run it regularly, say every minute, every ten
  • 0:08 - 0:12
    minutes, whatever, to update the announcement. So to set up
  • 0:12 - 0:15
    your cron job, you're going to need to create
  • 0:15 - 0:20
    a cron.xml file and configure it to run /cron/set_announcement
  • 0:20 - 0:22
    because that's the path that we set up for
  • 0:22 - 0:25
    our set, set announcement function. And then specify the schedule,
  • 0:25 - 0:28
    let's say once per minute. The development server on
  • 0:28 - 0:32
    localhost doesn't run cron jobs, so when you're ready, go
  • 0:32 - 0:35
    ahead and deploy your app to appspot. Then add one
  • 0:35 - 0:39
    or more conferences that have between zero and five seats
  • 0:39 - 0:41
    available. And the easiest way to do that is
  • 0:41 - 0:44
    just to create a new conference with max attendees less
  • 0:44 - 0:47
    than five. And then use the cron viewer in the
  • 0:47 - 0:50
    Admin Console to make sure that your cron job's running.
  • 0:50 - 0:52
    And then of course go ahead and get the latest
  • 0:52 - 0:56
    announcement to check that the latest announcement did get updated. And
  • 0:56 - 1:00
    you can do this either, you can use either the mem-cache
  • 1:00 - 1:04
    viewer or the API's console to get the latest announcement. So
  • 1:04 - 1:06
    now your cron job is humming along, it'll keep going
  • 1:06 - 1:09
    by itself. That means it's going to run a query to look
  • 1:09 - 1:12
    for conferences every minute, or however often you scheduled it to
  • 1:12 - 1:16
    run. It's helpful for learning purposes to see the cron job
  • 1:16 - 1:19
    running frequently, but it's not a good practice to leave cron
  • 1:19 - 1:22
    jobs running more frequently than you really need them. This cron job
  • 1:22 - 1:25
    does a fairly simple query, and then puts a value in mem
  • 1:25 - 1:28
    cache, for which there's no daily quota. But if your cron job
  • 1:28 - 1:31
    did something that intensively hit the data store it could easily use
  • 1:31 - 1:34
    up much more quota. So you need to think about what your
  • 1:34 - 1:38
    cron jobs do and how often they need to run. I've accidentally
  • 1:38 - 1:41
    used up my entire daily quota running a cron job that searched
  • 1:41 - 1:43
    all the conferences and saved results in the data store, so
  • 1:43 - 1:45
    I learned my lesson the hard way. So go ahead and
  • 1:45 - 1:48
    change the frequency to once an hour and when you've done
  • 1:48 - 1:53
    that come over here and check this box. Alternatively, you could disable
  • 1:53 - 1:56
    the cron job completely by uploading an empty cron job config,
  • 1:56 - 2:00
    but remember if you just delete the cron config file completely
  • 2:00 - 2:02
    then the one that's already up on app spot stays running.
  • 2:02 - 2:06
    So one more quick quiz. How do you schedule your cron job
  • 2:06 - 2:09
    to run once every two hours? Go ahead and enter
  • 2:09 - 2:12
    that value in here. And that's it for cron jobs.
タイトル:
Set Up a Cron Job - Developing Scalable Apps with Java
概説:

05-24 Set Up a Cron Job

more » « less
Video Language:
English
Team:
Udacity
プロジェクト:
UD859 - Developing Scalable Apps
Duration:
02:13

English subtitles

改訂 Compare revisions