[autotest] Add heartbeat AFE endpoint to shard Autotest

To improve the workload the autotest setup can handle, jobs should
be executed by multiple shards. They are sharded by type of board.

This a HTTP accessible endpoint to AFE. This assigns jobs and hosts
to moblabs and returns them as records to insert into a shard's
local database.

TEST=Ran suites and tried manually retrieving jobs
DEPLOY=scheduler,apache,host-scheduler

Change-Id: I20ac41364e4c67e17883729181af798e18d8093e
Reviewed-on: https://chromium-review.googlesource.com/217968
Reviewed-by: Jakob Jülich <jakobjuelich@chromium.org>
Reviewed-by: Fang Deng <fdeng@chromium.org>
Commit-Queue: Jakob Jülich <jakobjuelich@chromium.org>
Tested-by: Jakob Jülich <jakobjuelich@chromium.org>
diff --git a/frontend/afe/json_rpc/serviceHandler.py b/frontend/afe/json_rpc/serviceHandler.py
index b0d9e84..a66bb0d 100644
--- a/frontend/afe/json_rpc/serviceHandler.py
+++ b/frontend/afe/json_rpc/serviceHandler.py
@@ -21,9 +21,23 @@
 
 import traceback
 
-from json import decoder, encoder
+from json import decoder
+
+try:
+    from django.core import exceptions as django_exceptions
+    # Django JSON encoder uses the standard json encoder but can handle DateTime
+    from django.core.serializers import json as django_encoder
+    json_encoder = django_encoder.DjangoJSONEncoder()
+except django_exceptions.ImproperlyConfigured:
+    from json import encoder
+    json_encoder = encoder.JSONEncoder()
+
 from autotest_lib.client.common_lib.cros.graphite import stats
 
+
+json_decoder = decoder.JSONDecoder()
+
+
 def customConvertJson(value):
     """\
     Recursively process JSON values and do type conversions.
@@ -46,9 +60,6 @@
     else:
         return value
 
-json_encoder = encoder.JSONEncoder()
-json_decoder = decoder.JSONDecoder()
-
 
 def ServiceMethod(fn):
     fn.IsServiceMethod = True