Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show first run before job name & add global env vars #235

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Everything about how you want the scheduler to function is defined in a schedule

```yaml
tz_location: Europe/Brussels # optionally set timezone to adhere to
env: # env vars passed to any job.
foo: baz
jobs:
foo:
command: date
Expand All @@ -47,7 +49,7 @@ jobs:
command: # command to run, use a list if you want to pass args
- echo
- $foo
env: # you can pass env variables
env: # job-local env variables
foo: bar
other_workingdir:
command: pwd
Expand Down
8 changes: 8 additions & 0 deletions pkg/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,15 @@ func (j *JobSpec) execCommand(jr JobRun, trigger string) JobRun {
}

// Add env vars
// Firstly, add the system env vars
cmd.Env = os.Environ()

// Then add the global env vars from the schedule
for k, v := range j.globalSchedule.Env {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v))
}

// Then add the job specific env vars
for k, v := range j.Env {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v))
}
Expand Down
1 change: 1 addition & 0 deletions pkg/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Schedule struct {
OnSuccess OnEvent `yaml:"on_success,omitempty" json:"on_success,omitempty"`
OnError OnEvent `yaml:"on_error,omitempty" json:"on_error,omitempty"`
TZLocation string `yaml:"tz_location,omitempty" json:"tz_location,omitempty"`
Env map[string]secret `yaml:"env,omitempty"`
loc *time.Location
log zerolog.Logger
cfg Config
Expand Down
31 changes: 31 additions & 0 deletions pkg/web_assets/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,35 @@
src: url('/static/GeistMonoVariableVF.woff2') format('woff2');
font-weight: 100 900;
font-style: normal;
}

.tooltip {
position: relative;
display: inline-block;
}

.tooltip .tooltiptext {
visibility: hidden;
width: 200px;
background-color: rgba(0, 0, 0, 0.8);
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
padding: 10px;
font-size: 14px;
line-height: 1.4;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -60px;
opacity: 0;
transition: opacity 0.3s;
}

.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
47 changes: 42 additions & 5 deletions pkg/web_assets/templates/overview.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{{ define "content"}}
<div class="pt-4 pb-2">
<template x-for="job in $store.jobs.jobs" :key="job" x-data>
<template x-for="job in $store.jobs.jobs" x-data>
<div class="flex flex-wrap items-center">
<a class="pr-2 text-slate-200 hover:text-lime-200" :href="`/jobs/${job.name}/latest`" x-text="job.name"></a>
<!-- display only the most recent run before the job name -->
<template x-if="job.runs !== null">
<template x-for="run in job.runs">
<a class="pr-1" :href="`/jobs/${job.name}/${run.id}`"><abbr class="no-underline"
:title="`${truncateDateTime(run.triggered_at)}`">
<template x-for="(run, index) in job.runs" :key="index">
<template x-if="index === 0">
<a class="pr-2" :href="`/jobs/${job.name}/${run.id}`">
<abbr class="no-underline tooltip" :title="`${truncateDateTime(run.triggered_at)}`">
<span class="tooltiptext" x-text="`${truncateDateTime(run.triggered_at)}`"></span>

<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12"
:class="run.status === 0 ? 'fill-emerald-600' : run.status === undefined ? 'fill-orange-300' : 'fill-red-600'">
Expand All @@ -18,6 +20,41 @@
</svg>
</abbr>
</a>
</template>
</template>
</template>

<template x-if="job.runs === null">
<abbr class="no-underline pr-2 tooltip" title="never ran">
<span class="tooltiptext">never ran</span>
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" class="fill-slate-200">
<g>
<path
d="M6.03 1.01c-2.78 0-5.03 2.24-5.03 5.02s2.24 5.03 5.03 5.03 5.03-2.24 5.02-5.03-2.24-5.03-5.02-5.02z">
</path>
</g>
</svg>
</abbr>
</template>

<a class="pr-2 text-slate-200 hover:text-lime-200" :href="`/jobs/${job.name}/latest`" x-text="job.name"></a>
<template x-if="job.runs !== null">
<template x-for="(run, index) in job.runs" :key="index">
<template x-if="index !== 0">
<a class="pr-1" :href="`/jobs/${job.name}/${run.id}`">
<abbr class="no-underline tooltip" :title="`${truncateDateTime(run.triggered_at)}`">
<span class="tooltiptext" x-text="`${truncateDateTime(run.triggered_at)}`"></span>
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12"
:class="run.status === 0 ? 'fill-emerald-600' : run.status === undefined ? 'fill-orange-300' : 'fill-red-600'">
<g>
<path
d="M6.03 1.01c-2.78 0-5.03 2.24-5.03 5.02s2.24 5.03 5.03 5.03 5.03-2.24 5.02-5.03-2.24-5.03-5.02-5.02z">
</path>
</g>
</svg>
</abbr>
</a>
</template>
</template>
</template>
</div>
Expand Down
16 changes: 15 additions & 1 deletion testdata/jobs1.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
env:
FOO: baz
jobs:
foo:
command: date
Expand All @@ -22,4 +24,16 @@ jobs:
string_command:
command: echo foo bar
command_with_a_very_long_title:
command: echo foo bar
command: echo foo bar
global_env_var:
command:
- /bin/bash
- -c
- echo $FOO
local_env_var:
env:
FOO: local
command:
- /bin/bash
- -c
- echo $FOO
6 changes: 5 additions & 1 deletion testdata/readme_example.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
tz_location: Europe/Brussels # optionally set timezone to adhere to
env: # env vars passed to any job.
foo: baz
jobs:
foo:
command: date
Expand All @@ -10,7 +12,7 @@ jobs:
command: # command to run, use a list if you want to pass args
- echo
- $foo
env: # you can pass env variables
env: # job-local env variables
foo: bar
other_workingdir:
command: pwd
Expand All @@ -22,3 +24,5 @@ jobs:
on_error:
notify_webhook: # notify something on error
- https://webhook.site/4b732eb4-ba10-4a84-8f6b-30167b2f2762
notify_slack_webhook: # notify slack via a slack compatible webhook
- https://webhook.site/048ff47f-9ef5-43fb-9375-a795a8c5cbf5