Skip to content

Commit

Permalink
feat: Improve Slack schedule error handler and default to it
Browse files Browse the repository at this point in the history
  • Loading branch information
gbouv committed Oct 12, 2023
1 parent d51fc57 commit e895171
Show file tree
Hide file tree
Showing 9 changed files with 1,672 additions and 705 deletions.
Empty file modified backend/windmill-api-client/bundle.sh
100644 → 100755
Empty file.
1,978 changes: 1,358 additions & 620 deletions backend/windmill-api/openapi-deref.yaml

Large diffs are not rendered by default.

87 changes: 49 additions & 38 deletions backend/windmill-api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,36 @@ paths:
schema:
type: string

/w/{workspace}/workspaces/send_test_slack_error:
post:
summary: send test error to Slack to validate connection
operationId: sendTestSlackError
tags:
- workspace
parameters:
- $ref: "#/components/parameters/WorkspaceId"
requestBody:
description: WorkspaceInvite
required: true
content:
application/json:
schema:
type: object
properties:
channel:
type: string

responses:
"200":
description: status
content:
text/json:
schema:
type: object
properties:
submitted_job_uuid:
type: string

/w/{workspace}/workspaces/edit_deploy_to:
post:
summary: edit deploy to
Expand Down Expand Up @@ -2056,8 +2086,7 @@ paths:

/w/{workspace}/resources/get_value_interpolated/{path}:
get:
summary:
get resource interpolated (variables and resources are fully unrolled)
summary: get resource interpolated (variables and resources are fully unrolled)
operationId: getResourceValueInterpolated
tags:
- resource
Expand Down Expand Up @@ -2636,8 +2665,7 @@ paths:
schema:
type: string
- name: first_parent_hash
description:
mask to filter scripts whom first direct parent has exact hash
description: mask to filter scripts whom first direct parent has exact hash
in: query
schema:
type: string
Expand Down Expand Up @@ -2805,8 +2833,7 @@ paths:

/workers/custom_tags:
get:
summary:
get all instance custom tags (tags are used to dispatch jobs to
summary: get all instance custom tags (tags are used to dispatch jobs to
different worker groups)
operationId: getCustomTags
tags:
Expand Down Expand Up @@ -2857,8 +2884,7 @@ paths:

/w/{workspace}/scripts/delete/h/{hash}:
post:
summary:
delete script by hash (erase content but keep hash, require admin)
summary: delete script by hash (erase content but keep hash, require admin)
operationId: deleteScriptByHash
tags:
- script
Expand Down Expand Up @@ -3050,16 +3076,14 @@ paths:
type: string
format: date-time
- name: scheduled_in_secs
description:
schedule the script to execute in the number of seconds starting now
description: schedule the script to execute in the number of seconds starting now
in: query
schema:
type: integer
- $ref: "#/components/parameters/ParentJob"
- $ref: "#/components/parameters/NewJobId"
- name: invisible_to_owner
description:
make the run invisible to the the script owner (default false)
description: make the run invisible to the the script owner (default false)
in: query
schema:
type: boolean
Expand Down Expand Up @@ -4005,17 +4029,15 @@ paths:
type: string
format: date-time
- name: scheduled_in_secs
description:
schedule the script to execute in the number of seconds starting now
description: schedule the script to execute in the number of seconds starting now
in: query
schema:
type: integer
- $ref: "#/components/parameters/ParentJob"
- $ref: "#/components/parameters/NewJobId"
- $ref: "#/components/parameters/IncludeHeader"
- name: invisible_to_owner
description:
make the run invisible to the the flow owner (default false)
description: make the run invisible to the the flow owner (default false)
in: query
schema:
type: boolean
Expand Down Expand Up @@ -4053,17 +4075,15 @@ paths:
type: string
format: date-time
- name: scheduled_in_secs
description:
schedule the script to execute in the number of seconds starting now
description: schedule the script to execute in the number of seconds starting now
in: query
schema:
type: integer
- $ref: "#/components/parameters/ParentJob"
- $ref: "#/components/parameters/NewJobId"
- $ref: "#/components/parameters/IncludeHeader"
- name: invisible_to_owner
description:
make the run invisible to the the script owner (default false)
description: make the run invisible to the the script owner (default false)
in: query
schema:
type: boolean
Expand Down Expand Up @@ -4094,8 +4114,7 @@ paths:
- $ref: "#/components/parameters/WorkspaceId"
- $ref: "#/components/parameters/IncludeHeader"
- name: invisible_to_owner
description:
make the run invisible to the the script owner (default false)
description: make the run invisible to the the script owner (default false)
in: query
schema:
type: boolean
Expand Down Expand Up @@ -4128,8 +4147,7 @@ paths:
- $ref: "#/components/parameters/WorkspaceId"
- $ref: "#/components/parameters/IncludeHeader"
- name: invisible_to_owner
description:
make the run invisible to the the script owner (default false)
description: make the run invisible to the the script owner (default false)
in: query
schema:
type: boolean
Expand Down Expand Up @@ -4344,8 +4362,7 @@ paths:
- job
responses:
"200":
description:
the timestamp of the db that can be used to compute the drift
description: the timestamp of the db that can be used to compute the drift
content:
application/json:
schema:
Expand Down Expand Up @@ -4578,8 +4595,7 @@ paths:

/w/{workspace}/jobs/resume_urls/{id}/{resume_id}:
get:
summary:
get resume urls given a job_id, resume_id and a nonce to resume a flow
summary: get resume urls given a job_id, resume_id and a nonce to resume a flow
operationId: getResumeUrls
tags:
- job
Expand Down Expand Up @@ -5092,8 +5108,7 @@ paths:
- $ref: "#/components/parameters/WorkspaceId"
- name: only_member_of
in: query
description:
only list the groups the user is member of (default false)
description: only list the groups the user is member of (default false)
schema:
type: boolean
responses:
Expand Down Expand Up @@ -5281,8 +5296,7 @@ paths:
- $ref: "#/components/parameters/WorkspaceId"
- name: only_member_of
in: query
description:
only list the folders the user is member of (default false)
description: only list the folders the user is member of (default false)
schema:
type: boolean
responses:
Expand Down Expand Up @@ -6000,8 +6014,7 @@ components:
type: integer
PerPage:
name: per_page
description:
number of items to return for a given page (default 30, max 100)
description: number of items to return for a given page (default 30, max 100)
in: query
schema:
type: integer
Expand Down Expand Up @@ -6135,8 +6148,7 @@ components:
type: boolean
ArgsFilter:
name: args
description:
filter on jobs containing those args as a json subset (@> in postgres)
description: filter on jobs containing those args as a json subset (@> in postgres)
in: query
schema:
type: string
Expand All @@ -6148,8 +6160,7 @@ components:
type: string
ResultFilter:
name: result
description:
filter on jobs containing those result as a json subset (@> in postgres)
description: filter on jobs containing those result as a json subset (@> in postgres)
in: query
schema:
type: string
Expand Down
63 changes: 63 additions & 0 deletions backend/windmill-api/src/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ use axum::{
routing::{delete, get, post},
Json, Router,
};
use chrono::Utc;
use magic_crypt::MagicCryptTrait;
use serde_json::json;
#[cfg(feature = "enterprise")]
use stripe::CustomerId;
use windmill_audit::{audit_log, ActionKind};
use windmill_common::db::UserDB;
use windmill_common::jobs::JobPayload;
use windmill_common::schedule::Schedule;
use windmill_common::users::username_to_permissioned_as;
use windmill_common::{
Expand All @@ -52,6 +55,7 @@ use sqlx::{FromRow, Postgres, Transaction};
use tempfile::TempDir;
use tokio::fs::File;
use tokio_util::io::ReaderStream;
use windmill_queue::PushIsolationLevel;

pub fn workspaced_service() -> Router {
let router = Router::new()
Expand All @@ -64,6 +68,7 @@ pub fn workspaced_service() -> Router {
.route("/get_settings", get(get_settings))
.route("/get_deploy_to", get(get_deploy_to))
.route("/edit_slack_command", post(edit_slack_command))
.route("/send_test_slack_error", post(send_test_slack_error))
.route("/edit_webhook", post(edit_webhook))
.route("/edit_auto_invite", post(edit_auto_invite))
.route("/edit_deploy_to", post(edit_deploy_to))
Expand Down Expand Up @@ -149,6 +154,15 @@ struct EditCommandScript {
slack_command_script: Option<String>,
}

#[derive(Deserialize)]
struct SendTestSlackError {
channel: String,
}

#[derive(Serialize)]
struct SendTestSlackErrorResponse {
submitted_job_uuid: String,
}

#[cfg(feature = "enterprise")]
#[derive(Deserialize)]
Expand Down Expand Up @@ -507,6 +521,55 @@ async fn edit_slack_command(
Ok(format!("Edit command script {}", &w_id))
}

async fn send_test_slack_error(
authed: ApiAuthed,
Extension(db): Extension<DB>,
Extension(rsmq): Extension<Option<rsmq_async::MultiplexedRsmq>>,
Path(w_id): Path<String>,
Json(es): Json<SendTestSlackError>,
) -> JsonResult<SendTestSlackErrorResponse> {

let payload = JobPayload::ScriptHub { path: "hub/2431/slack/schedule-error-handler-slack".to_string() };

let mut job_args = serde_json::Map::new();
job_args.insert("path".to_string(), json!("slack_notification_test"));
job_args.insert("is_flow".to_string(), json!(false));
job_args.insert("schedule_path".to_string(), json!("slack_notification_test"));
job_args.insert("error".to_string(), json!(format!("This is a notification to test the connection between Windmill workspace '{}' and Slack", w_id)));
job_args.insert("start_at".to_string(), json!(Utc::now()));
job_args.insert("failed_times".to_string(), json!(0));
job_args.insert("slack".to_string(), json!("$res:f/slack_bot/bot_token")); // TODO: include in the request maybe?
job_args.insert("channel".to_string(),json!(es.channel));

let tx = PushIsolationLevel::IsolatedRoot(db.clone(), rsmq);
let (uuid, tx) = windmill_queue::push(
&db,
tx,
w_id.as_str(),
payload,
job_args,
authed.username.as_str(),
authed.email.as_str(),
username_to_permissioned_as(authed.username.as_str()), // TODO: check with ruben if this is correct
None,
None,
None,
None,
None,
false,
false,
None,
true,
None, // Maybe add a specific tag to track those "test" jobs?
None,
None
).await?;
tx.commit().await?;

Ok(Json(SendTestSlackErrorResponse {
submitted_job_uuid: uuid.to_string(),
}))
}

#[cfg(feature = "enterprise")]
async fn edit_deploy_to(
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lib/components/ArgInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
export let resourceTypes: string[] | undefined
export let disablePortal = false
export let showSchemaExplorer = false
export let simpleTooltip: string | undefined = undefined
let seeEditable: boolean = enum_ != undefined || pattern != undefined
const dispatch = createEventDispatcher()
Expand Down Expand Up @@ -187,7 +188,7 @@
<div class="flex flex-col w-full {minW ? 'min-w-[250px]' : ''}">
<div>
{#if displayHeader}
<FieldHeader prettify={prettifyHeader} {label} {required} {type} {contentEncoding} {format} />
<FieldHeader prettify={prettifyHeader} {label} {required} {type} {contentEncoding} {format} {simpleTooltip} />
{/if}
{#if editableSchema}
<label class="text-secondary">
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/lib/components/FieldHeader.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts">
import { twMerge } from 'tailwind-merge'
import Required from './Required.svelte'
import { capitalize } from '$lib/utils'
import Tooltip from '$lib/components/Tooltip.svelte'
import { capitalize, emptyString } from '$lib/utils'
export let label: string
export let format: string = ''
Expand All @@ -11,6 +12,7 @@
export let displayType: boolean = true
export let labelClass: string = ''
export let prettify = false
export let simpleTooltip: string | undefined
</script>

<div class="inline-flex flex-row items-center truncated">
Expand All @@ -36,4 +38,12 @@
</span>
{/if}
{/if}

{#if !emptyString(simpleTooltip)}
<Tooltip class="ml-2">
<span class="text-xs">
{simpleTooltip}
</span>
</Tooltip>
{/if}
</div>
Loading

0 comments on commit e895171

Please sign in to comment.