Cron lines
The next times a cron line runs, and whether it is valid: show a schedule, or run your own.
Version 1.0.0 · 2 functions · 2 crates
Functions
What use cron.qwer gives a program, with the types Quillo sees. To take only some, or under other names: use cron_next, cron_valid from cron (Quillo 0.6).
cron_next(line: str, count: int, after: int) → listor an errorThe next count times line runs after after (milliseconds since 1970; 0 for now), in UTC, as milliseconds.
cron_valid(line: str) → boolWhether line is a cron line this reads (5 fields, or 6 and 7 with seconds and years).
Get it
$ quillo install cron # cron.qwer into this folder$ quillo install cron --example # and its example, cron.qweOr with curl:
$ curl -O https://quillolang.org/plugins/files/cron.qwer$ curl -O https://quillolang.org/plugins/files/cron.qweThen, in your program, all of it or only what you call:
main.qwe
use cron.qweruse cron_next, cron_valid from cron // Quillo 0.6: only theseIt uses these crates, which cargo fetches the first time the plugin is built:
[dependencies]
cron = "0.12"chrono = "0.4"Example
cron.qwe
// A page that shows when each job runs next.//// quillo run cron.qwe then open http://localhost:8080/next?line=0+9+*+*+1-5use "cron.qwer"route GET /next ? { line: str } = cron_next(line, 5, 0)? | map((ms) => date.format(date.from_ms(ms), "yyyy-MM-dd HH:mm"))route GET /fixed = { runs: cron_next("30 2 * * *", 2, 1767225600000)?, valid: cron_valid("*/15 * * * *"), invalid: cron_valid("61 * * * *") }$ quillo run cron.qwe$ curl 'localhost:8080/next?line=0+9+*+*+1-5'$ curl 'localhost:8080/fixed'Source
cron.qwer
//! Cron lines read: the next times one runs, whether it is valid, for showing a schedule or running your own.//! version: 1.0.0//!//! [dependencies]//! cron = "0.12"//! chrono = "0.4"use chrono::{TimeZone, Utc};use std::str::FromStr;/// A 5-field line (`minute hour day month weekday`) given a seconds field, as the crate wants; 6 and 7 fields pass as they are.fn schedule(line: &str) -> Result<cron::Schedule, String> { let fields = line.split_whitespace().count(); let full = if fields == 5 { format!("0 {}", line.trim()) } else { line.trim().to_string() }; cron::Schedule::from_str(&full).map_err(|e| format!("`{}`: {}", line, e))}/// The next `count` times `line` runs after `after` (milliseconds since 1970; 0 for now), in UTC, as milliseconds.pub fn cron_next(line: &str, count: i64, after: i64) -> Result<Vec<i64>, String> { let s = schedule(line)?; let from = if after > 0 { Utc.timestamp_millis_opt(after).single().ok_or("a time out of range")? } else { Utc::now() }; Ok(s.after(&from).take(count.clamp(0, 1000) as usize).map(|t| t.timestamp_millis()).collect())}/// Whether `line` is a cron line this reads (5 fields, or 6 and 7 with seconds and years).pub fn cron_valid(line: &str) -> bool { schedule(line).is_ok()}Related
Opening hours
opening_hours.qwer · 1.0.0OpenStreetMap opening_hours strings such as "Mo-Fr 08:00-18:00; PH off": open now or not and until when, when it next opens, a week's hours table with the country's public holidays, and expressions checked and tidied.7 views · 7 downloadsBusiness days business_days.qwer · 1.0.0Working days for due dates, delivery estimates and SLAs: add them, count them between dates, skip weekends and holidays, with US, UK, French and German public holidays built in.6 views · 5 downloadsEnglish dates dates_english.qwer · 1.0.0Dates typed in English read as times, in the user's time zone and US or UK style: next friday at 3pm, tomorrow 9am, in 2 weeks, 3 days ago.8 views · 10 downloadsISO durations iso_durations.qwer · 1.0.0ISO 8601 durations such as P1DT2H and PT30M read, written, turned into seconds and added to dates and times, months moving the calendar.7 views · 9 downloadsKSUID ksuid.qwer · 1.0.0KSUIDs, Segment's K-Sortable Unique IDs: 27 base62 characters sorted by the second they were made, with 128 random bits; made, read back and checked.8 views · 7 downloadsSnowflake ids snowflake.qwer · 1.0.0Snowflake ids: 64-bit numbers that sort by time, unique across 1,024 servers with no coordination, with their time, server and sequence read back and the first id of a time for range queries.7 views · 7 downloadsThread
Thread 0 posts
On Cron lines: questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.