-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows for distributed list generation (#566)
- Loading branch information
Showing
14 changed files
with
219 additions
and
64 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import App from '../app' | ||
import { cacheIncr } from '../config/redis' | ||
import { Job } from '../queue' | ||
import { getUser } from '../users/UserRepository' | ||
import { DynamicList } from './List' | ||
import { CacheKeys, cleanupList, evaluateUserList, getList } from './ListService' | ||
|
||
interface ListEvaluateUserParams { | ||
listId: number | ||
userId: number | ||
projectId: number | ||
version: number | ||
totalCount: number | ||
} | ||
|
||
export default class ListEvaluateUserJob extends Job { | ||
static $name = 'list_evaluate_user_job' | ||
|
||
static from(params: ListEvaluateUserParams): ListEvaluateUserJob { | ||
return new this(params) | ||
} | ||
|
||
static async handler({ listId, userId, projectId, version, totalCount }: ListEvaluateUserParams) { | ||
|
||
const list = await getList(listId, projectId) as DynamicList | ||
if (!list) return | ||
|
||
// Check to see if we are still evaluating the latest | ||
// version of the list ruleset | ||
if (list.version !== version) return | ||
|
||
const evaluate = async () => { | ||
const user = await getUser(userId, projectId) | ||
if (!user) return | ||
await evaluateUserList(user, list) | ||
} | ||
|
||
// No matter what always increment the progress | ||
try { | ||
await evaluate() | ||
} finally { | ||
const cacheKey = CacheKeys.populationProgress(list) | ||
const count = await cacheIncr(App.main.redis, cacheKey, 1, 300) | ||
if (count >= totalCount) { | ||
await cleanupList(list) | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.