Skip to content

Commit

Permalink
change function args
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Jun 24, 2020
1 parent 6cc3f38 commit 6b3b93a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 38 deletions.
48 changes: 21 additions & 27 deletions x-pack/plugins/reporting/server/lib/esqueue/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,13 @@ export class Worker extends events.EventEmitter {
};

return this.queue.store
.updateReport(
{
index: job._index,
id: job._id,
if_seq_no: job._seq_no,
if_primary_term: job._primary_term,
},
doc
)
.updateReport({
index: job._index,
id: job._id,
if_seq_no: job._seq_no,
if_primary_term: job._primary_term,
body: { doc },
})
.then((response) => {
this.info(`Job marked as claimed: ${getUpdatedDocPath(response)}`);
const updatedJob = {
Expand Down Expand Up @@ -200,15 +198,13 @@ export class Worker extends events.EventEmitter {
});

return this.queue.store
.updateReport(
{
index: job._index,
id: job._id,
if_seq_no: job._seq_no,
if_primary_term: job._primary_term,
},
doc
)
.updateReport({
index: job._index,
id: job._id,
if_seq_no: job._seq_no,
if_primary_term: job._primary_term,
body: { doc },
})
.then((response) => {
this.info(`Job marked as failed: ${getUpdatedDocPath(response)}`);
})
Expand Down Expand Up @@ -299,15 +295,13 @@ export class Worker extends events.EventEmitter {
};

return this.queue.store
.updateReport(
{
index: job._index,
id: job._id,
if_seq_no: job._seq_no,
if_primary_term: job._primary_term,
},
doc
)
.updateReport({
index: job._index,
id: job._id,
if_seq_no: job._seq_no,
if_primary_term: job._primary_term,
body: { doc },
})
.then((response) => {
const eventOutput = {
job: formatJobObject(job),
Expand Down
41 changes: 40 additions & 1 deletion x-pack/plugins/reporting/server/lib/store/report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Class Report', () => {
priority: 1,
};
const report = new Report(opts);
expect(report).toMatchObject({
expect(report.toJSON()).toMatchObject({
_primary_term: undefined,
_seq_no: undefined,
browser_type: 'browser_type_test_string',
Expand All @@ -35,4 +35,43 @@ describe('Class Report', () => {

expect(report.id).toBeDefined();
});

it('updateWithDoc method syncs takes fields to sync ES metadata', () => {
const opts = {
index: '.reporting-test-index-12345',
jobtype: 'test-report',
created_by: 'created_by_test_string',
browser_type: 'browser_type_test_string',
max_attempts: 50,
payload: { payload_test_field: 1 },
timeout: 30000,
priority: 1,
};
const report = new Report(opts);

const metadata = {
_index: '.reporting-test-update',
_id: '12342p9o387549o2345',
_primary_term: 77,
_seq_no: 99,
};
report.updateWithDoc(metadata);

expect(report.toJSON()).toMatchObject({
index: '.reporting-test-update',
_primary_term: 77,
_seq_no: 99,
browser_type: 'browser_type_test_string',
created_by: 'created_by_test_string',
jobtype: 'test-report',
max_attempts: 50,
payload: {
payload_test_field: 1,
},
priority: 1,
timeout: 30000,
});

expect(report._id).toBe('12342p9o387549o2345');
});
});
21 changes: 11 additions & 10 deletions x-pack/plugins/reporting/server/lib/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import { ElasticsearchServiceSetup } from 'src/core/server';
import { LevelLogger } from '../';
import { ReportingCore } from '../../';
import { Report } from './report';
import { mapping } from './mapping';
import { indexTimestamp } from './index_timestamp';
import { LayoutInstance } from '../../export_types/common/layouts';
import { indexTimestamp } from './index_timestamp';
import { mapping } from './mapping';
import { Report } from './report';

export const statuses = {
JOB_STATUS_PENDING: 'pending',
Expand All @@ -28,11 +28,12 @@ interface AddReportOpts {
max_attempts: number;
}

interface UpdateOptions {
interface UpdateQuery {
index: string;
id: string;
if_seq_no: unknown;
if_primary_term: unknown;
body: { doc: Partial<Report> };
}

/*
Expand Down Expand Up @@ -165,13 +166,13 @@ export class ReportingStore {
return report;
}

public async updateReport(opts: UpdateOptions, doc: Partial<Report>): Promise<Report> {
public async updateReport(query: UpdateQuery): Promise<Report> {
return this.client.callAsInternalUser('update', {
index: opts.index,
id: opts.id,
if_seq_no: opts.if_seq_no,
if_primary_term: opts.if_primary_term,
body: { doc },
index: query.index,
id: query.id,
if_seq_no: query.if_seq_no,
if_primary_term: query.if_primary_term,
body: { doc: query.body.doc },
});
}
}

0 comments on commit 6b3b93a

Please sign in to comment.