|
4 | 4 | from django.conf import settings |
5 | 5 | from django.contrib.staticfiles.storage import staticfiles_storage |
6 | 6 |
|
7 | | -from .exceptions import WebpackError, WebpackLoaderBadStatsError |
| 7 | +from .exceptions import ( |
| 8 | + WebpackError, |
| 9 | + WebpackLoaderBadStatsError, |
| 10 | + WebpackLoaderTimeoutError |
| 11 | +) |
8 | 12 | from .config import load_config |
9 | 13 |
|
10 | 14 |
|
@@ -53,13 +57,24 @@ def get_chunk_url(self, chunk): |
53 | 57 | def get_bundle(self, bundle_name): |
54 | 58 | assets = self.get_assets() |
55 | 59 |
|
| 60 | + # poll when debugging and block request until bundle is compiled |
| 61 | + # or the build times out |
56 | 62 | if settings.DEBUG: |
57 | | - # poll when debugging and block request until bundle is compiled |
58 | | - # TODO: support timeouts |
59 | | - while assets['status'] == 'compiling': |
| 63 | + timeout = self.config['TIMEOUT'] or 0 |
| 64 | + timed_out = False |
| 65 | + start = time.time() |
| 66 | + while assets['status'] == 'compiling' and not timed_out: |
60 | 67 | time.sleep(self.config['POLL_INTERVAL']) |
| 68 | + if timeout and (time.time() - timeout > start): |
| 69 | + timed_out = True |
61 | 70 | assets = self.get_assets() |
62 | 71 |
|
| 72 | + if timed_out: |
| 73 | + raise WebpackLoaderTimeoutError( |
| 74 | + "Timed Out. Bundle `{0}` took more than {1} seconds " |
| 75 | + "to compile.".format(bundle_name, timeout) |
| 76 | + ) |
| 77 | + |
63 | 78 | if assets.get('status') == 'done': |
64 | 79 | chunks = assets['chunks'][bundle_name] |
65 | 80 | return self.filter_chunks(chunks) |
|
0 commit comments