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

Switch to using agenda for scheduling #189

Closed
orta opened this issue Jan 20, 2018 · 2 comments
Closed

Switch to using agenda for scheduling #189

orta opened this issue Jan 20, 2018 · 2 comments

Comments

@orta
Copy link
Member

orta commented Jan 20, 2018

So we can do "in one week" or whatever

@orta
Copy link
Member Author

orta commented Jan 24, 2018

An ideal API, expanding on this Dangerfile from the Artsy Peril setup for new RFCs.

import { danger } from "danger"
import { IncomingWebhook } from "@slack/client"
import { Issues } from "github-webhook-event-types"

declare const peril: any // danger/danger#351

const gh = (danger.github as any) as Issues
const issue = gh.issue

if (issue.title.includes("RFC:")) {
  var url = peril.env.SLACK_RFC_WEBHOOK_URL || ""
  var webhook = new IncomingWebhook(url)
  webhook.send({})

  // Remind us halfway, and at the end of the week to write comments
  peril.runTask('mid_week_rfc_notification', 'in 3 days', issue)
  peril.runTask('end_of_week_rfc_notification', 'in 7 days', issue)
}

This would be hooked up inside the peril settings, where you can define your tasks and their corresponding files:

{
  "rules": {
    "pull_request": "artsy/artsy-danger@org/all-prs.ts",
    "pull_request.closed": "artsy/artsy-danger@org/closed-prs.ts"
  },
  "repos": {
    "artsy/reaction": {
      "pull_request": "danger/pr.ts"
  },
  "tasks": {
    "mid_week_rfc_notification": "artsy/artsy-danger@tasks/rfc/mid_week.ts",
    "end_of_week_rfc_notification": "artsy/artsy-danger@tasks/rfc/mid_week.ts"
  }
}

Here's an example task: tasks/rfc/mid_week.ts

import { peril } from "danger"
import { IncomingWebhook } from "@slack/client"
import { Issues } from "github-webhook-event-types"

const issue = peril.data as Issues

var url = peril.env.SLACK_RFC_WEBHOOK_URL || ""
var webhook = new IncomingWebhook(url)
webhook.send({ // in 3 days etc })

the issue JSON is passed from the peril.schedule to peril.data.

@orta
Copy link
Member Author

orta commented Jan 24, 2018

Under the hood:

Today: peril.schedule could make those calls directly to the peril internals.

In the future: is going to have to send something back to the host process.

It's probably better to make the scheduler a separate API route POST, it should take a task name, an interval and some dumb json data. Under the hood it can call

agenda.schedule('3 days', 'runDangerTask', { name: "mid_week_rfc_notification", data: issue });

Which can get hooked up to a generic task runner inside Peril.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant