Follow the Database Access with Python instructions . In the U19_pipeline_python repository, open the u19_pipeline/alert_system/custom_alerts directory. Create a new Python file with a meaningful name for the alert (e.g. subject_bias.py). Copy the skeleton code from u19_pipeline/alert_system/alert_code_skeleton.py. All Slack alert code has two parts: a Slack channel configuration and a main function , described in the next sections. This function should return a pandas DataFrame in which each row is a Slack alert message on the configured channels. You can use DataJoint to get data for the alert (e.g. custom_alerts/rig_bias.py) or simply call OS scripts (e.g. custom_alerts/braininit_storage.py). All columns of the DataFrame are included in the alert. (Don't add too many!) DataFrame example with a Slack notification message: You can check examples of some alerts in the u19_pipeline/alert_system/custom_alerts directory. The Slack channel configuration is a dictionary that links the corresponding Slack channels and conversations with a specific alert. The dictionary has two keys: 'slack_notification_channel' and 'slack_users_channel'. slack_notification_channel General channel names to send notifications to.slack_users_channel Private direct messages to send notifications to.You can add a list of channels to each of the keys: slack_notification_channel Any webhook_name (see the next section).slack_users_channel Any user_id with a configured slack_webhook (see the next section).Execute fetch(lab.SlackWebhooks,'*'). Execute: lab = dj.create_virtual_module('lab', 'u19_lab')lab.SlackWebhooks.fetch(as_dict=True) Execute: fetch ( lab. User & "slack_webhook < > '' ", 'slack_webhook' )
Execute:lab = dj. create_virtual_module( 'lab' , 'u19_lab' )
( lab. User & "slack_webhook <> ''" ) . fetch( 'KEY' , 'slack_webhook' , as_dict= True )
Create a new Slack channel if needed (for notification channels). Follow the instructions to create webhooks from the Slack documentation . Copy the Slack webhook from the Slack API web page. new_slack_webhook = struct
new_slack_webhook. webhook_name = ( notification channel name)
new_slack_webhook. webhook_url = ( webhook url from slack API)
insert ( lab. SlackWebhooks, new_slack_webhook)
lab = dj. create_virtual_module( 'lab' , 'u19_lab' )
new_slack_webhook = dict ( )
new_slack_webhook[ 'webhook_name' ] = ( notification channel name)
new_slack_webhook[ 'webhook_url' ] = ( webhook url from slack API)
lab. SlackWebhooks. insert1( new_slack_webhook)
user = struct
user. user_id = ( NETID of user)
update ( lab. User & user, 'slack_webhook' , ( webhook url from slack API) )
lab = dj. create_virtual_module( 'lab' , 'u19_lab' )
user = dict ( )
user[ 'user_id' ] = ( NETID of user)
user[ 'slack_webhook' ] = ( webhook url from slack API)
lab. User. update1( user)
Automated cronjobs in BRAINCoGS (Developer Guide) Subtask pipeline