Skip to content

Commit 4f48240

Browse files
committed
typo fix and sets timeout to 5 seconds
1 parent 7615d79 commit 4f48240

8 files changed

Lines changed: 19 additions & 19 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ cp config.example.yml config.yml
3232
Edit `config.yml` and add API tokens per source in `cron.sources` (via `api_token`).
3333
If a source should skip historical fetches, set `only_get_current: true` on that source.
3434
You can also set `resolution` per source to override provider defaults (for example ElectricityMaps `5_minutes`).
35-
Set `update_iterval` (seconds) on a source to run it less frequently than the global cron loop (`run_cron_checker_seconds`).
35+
Set `update_interval` (seconds) on a source to run it less frequently than the global cron loop (`run_cron_checker_seconds`).
3636

3737
For ElectricityMaps: Replace "your-electricitymaps-api-token-here" with your actual token. You don't need to modify anything to start collection. We use free endpoints per default.
3838

@@ -55,7 +55,7 @@ and that should set everythin up so that you can access Elephant under `http://l
5555

5656
In production you typically need an SSL certificate to run Elephant.
5757

58-
Here we recommend you to use an NGINX reverse proxy and use its SSL certificate handling.
58+
Here we recommend you to use an NGINX reverse proxy and use its SSL certificate handling.
5959
Then bind the Elephant `app` container only to localhost.
6060

6161
Change the `ports` directive from `8085:8085` to `127.0.0.1:8085:8085`.

config.example.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ cron:
1111
sources:
1212
- region: "DE"
1313
provider: "bundesnetzagentur"
14-
# update_iterval: 3600 # seconds
14+
# update_interval: 3600 # seconds
1515
primary: true # If you have multiple sources for the same region, one should be marked as primary so the api knows which to return by default
1616
- region: "DE"
1717
provider: "energycharts"
18-
# update_iterval: 1800 # seconds
18+
# update_interval: 1800 # seconds
1919
# - region: "DE"
2020
# provider: "bundesnetzagentur_all"
2121
# - region: "DE"
2222
# provider: "electricitymaps"
2323
# api_token: "YOUR TOKEN HERE"
2424
# resolution: "5_minutes"
25-
# update_iterval: 3600 # every hour
25+
# update_interval: 3600 # every hour
2626
# only_get_current: true
2727
# primary: true
2828
# - region: "FR"
2929
# provider: "electricitymaps"
3030
# api_token: "YOUR TOKEN HERE"
3131
# resolution: "5_minutes"
32-
# update_iterval: 3600 # every hour
32+
# update_interval: 3600 # every hour
3333
# only_get_current: false
3434

3535
# Logging

elephant/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Source(BaseModel):
3333
provider: str
3434
api_token: Optional[str] = None
3535
resolution: Optional[str] = None
36-
update_iterval: Optional[int] = Field(default=None, ge=1)
36+
update_interval: Optional[int] = Field(default=None, ge=1)
3737
only_get_current: bool = False
3838
primary: bool = False
3939

elephant/cron.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ def run_cron(specific_region=None, specific_provider=None) -> None:
8585
logger.warning("Provider '%s' for region '%s' is not configured or enabled.", provider_db_name, region)
8686
continue
8787

88-
if not _is_source_due(cur, provider_db_name, source.update_iterval, force_run=force_run):
88+
if not _is_source_due(cur, provider_db_name, source.update_interval, force_run=force_run):
8989
logger.debug(
90-
"Skipping '%s' due to update_iterval=%s seconds.",
90+
"Skipping '%s' due to update_interval=%s seconds.",
9191
provider_db_name,
92-
source.update_iterval,
92+
source.update_interval,
9393
)
9494
continue
9595

elephant/providers/bna_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
def fetch_json(url: str) -> Optional[dict]:
5757
try:
58-
response = requests.get(url, timeout=30.0)
58+
response = requests.get(url, timeout=5.0)
5959
response.raise_for_status()
6060
return response.json()
6161
except (requests.RequestException, ValueError):

elephant/providers/electricitymaps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, config: ProviderConfig):
3333
def _get(self, path: str, params: dict) -> Response:
3434
"""Perform a GET request with shared error handling."""
3535
try:
36-
response = requests.get(f"{BASE_URL}{path}", params=params, timeout=30.0, headers=self.headers)
36+
response = requests.get(f"{BASE_URL}{path}", params=params, timeout=5.0, headers=self.headers)
3737
response.raise_for_status()
3838
return response
3939

elephant/providers/energycharts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, config: ProviderConfig):
2929
def _get(self, region: str) -> dict:
3030
"""Perform a GET request with shared error handling."""
3131
try:
32-
response = requests.get(f"{BASE_URL}/co2eq", params={"country": region.lower()}, timeout=30.0)
32+
response = requests.get(f"{BASE_URL}/co2eq", params={"country": region.lower()}, timeout=5.0)
3333
response.raise_for_status()
3434
return response.json()
3535
except (HTTPError, RequestException) as exc:

tests/test_cron.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ def _fake_db_connection():
142142
assert conn.commits == 1
143143

144144

145-
def test_run_cron_skips_source_if_update_iterval_not_elapsed(monkeypatch) -> None:
145+
def test_run_cron_skips_source_if_update_interval_not_elapsed(monkeypatch) -> None:
146146
provider = _CountingProvider()
147-
cfg = _make_config(Source(region="DE", provider="energycharts", update_iterval=15))
147+
cfg = _make_config(Source(region="DE", provider="energycharts", update_interval=15))
148148
conn = _FakeConnection()
149149
conn.last_runs["energycharts_de"] = datetime.now(tz=timezone.utc)
150150

@@ -164,9 +164,9 @@ def _fake_db_connection():
164164
assert conn.commits == 0
165165

166166

167-
def test_run_cron_runs_source_if_update_iterval_elapsed(monkeypatch) -> None:
167+
def test_run_cron_runs_source_if_update_interval_elapsed(monkeypatch) -> None:
168168
provider = _CountingProvider()
169-
cfg = _make_config(Source(region="DE", provider="energycharts", update_iterval=15))
169+
cfg = _make_config(Source(region="DE", provider="energycharts", update_interval=15))
170170
conn = _FakeConnection()
171171
previous_run = datetime.now(tz=timezone.utc) - timedelta(seconds=16)
172172
conn.last_runs["energycharts_de"] = previous_run
@@ -188,9 +188,9 @@ def _fake_db_connection():
188188
assert conn.last_runs["energycharts_de"] > previous_run
189189

190190

191-
def test_run_cron_force_run_bypasses_update_iterval(monkeypatch) -> None:
191+
def test_run_cron_force_run_bypasses_update_interval(monkeypatch) -> None:
192192
provider = _CountingProvider()
193-
cfg = _make_config(Source(region="DE", provider="energycharts", update_iterval=30))
193+
cfg = _make_config(Source(region="DE", provider="energycharts", update_interval=30))
194194
conn = _FakeConnection()
195195
conn.last_runs["energycharts_de"] = datetime.now(tz=timezone.utc)
196196

0 commit comments

Comments
 (0)