Skip to content

Commit

Permalink
feat: [#38] Extract new ID generation to a separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
yeraydavidrodriguez committed May 4, 2022
1 parent e21b0d7 commit bcb2575
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion __tests__/unit/commit-subject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('CommitSubject', () => {
)

const commit3 = CommitSubjectParser.parseText(
'📝🈺: otherqueue: not queue job.id.1 commit-no prefix'
'📝🈺: other-queue: not queue job.id.1 commit-no prefix'
)
expect(commit3.belongsToQueue(new QueueName('standard commit'))).toBe(false)
})
Expand Down
13 changes: 8 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,21 @@ export class Queue {

// Job states: new -> started -> finished

async createJob(payload: string): Promise<Job> {
getNextJobId(): number {
const latestMessage = this.getLatestMessage()
this.guardThatLastMessageWasJobFinishedOrNull(latestMessage)

const newJobId = latestMessage.isNull() ? 0 : latestMessage.jobId() + 1
return latestMessage.isNull() ? 0 : latestMessage.jobId() + 1
}

async createJob(payload: string): Promise<Job> {
const nextJobId = this.getNextJobId()

const message = new NewJobMessage(payload, newJobId)
const message = new NewJobMessage(payload, nextJobId)

const commit = await this.commitMessage(message)

return new Job(payload, commit.hash, newJobId)
return new Job(payload, commit.hash, nextJobId)
}

async markJobAsStarted(payload: string): Promise<CommitInfo> {
Expand Down

0 comments on commit bcb2575

Please sign in to comment.