-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Translate slack importer into an oban worker
The slack importer now uses one call for each update, rather than fetching and separately writing for each member.
- Loading branch information
Showing
6 changed files
with
41 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule Changelog.ObanWorkers.SlackImporter do | ||
use Oban.Worker, queue: :scheduled | ||
|
||
alias Changelog.{Person, Repo} | ||
alias Changelog.Slack.Client | ||
|
||
import Ecto.Query | ||
|
||
@impl Oban.Worker | ||
def perform(_job) do | ||
%{"members" => members} = Client.list() | ||
|
||
for %{"id" => id, "profile" => profile} <- members do | ||
email = Map.get(profile, "email", "") | ||
|
||
import_member_id(id, email) | ||
end | ||
|
||
:ok | ||
end | ||
|
||
def import_member_id(id, email) do | ||
Person | ||
|> where([p], p.email == ^email) | ||
|> where([p], is_nil(p.slack_id) or p.slack_id == "pending") | ||
|> Repo.update_all(set: [slack_id: id]) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters