Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions interceptors/LogFailedJobsInterceptor.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ component {
},
"exceptionType" : {
"value" : arguments.data.exception.type ?: "",
"cfsqltype" : "CF_SQL_VARCHAR",
"cfsqltype" : "CF_SQL_LONGVARCHAR",
"null" : ( arguments.data.exception.type ?: "" ) == "",
"nulls" : ( arguments.data.exception.type ?: "" ) == ""
},
"exceptionMessage" : {
"value" : arguments.data.exception.message ?: "",
"cfsqltype" : "CF_SQL_VARCHAR",
"cfsqltype" : "CF_SQL_LONGVARCHAR",
"null" : ( arguments.data.exception.message ?: "" ) == "",
"nulls" : ( arguments.data.exception.message ?: "" ) == ""
},
"exceptionDetail" : {
"value" : arguments.data.exception.detail ?: "",
"cfsqltype" : "CF_SQL_VARCHAR",
"cfsqltype" : "CF_SQL_LONGVARCHAR",
"null" : ( arguments.data.exception.detail ?: "" ) == "",
"nulls" : ( arguments.data.exception.detail ?: "" ) == ""
},
Expand Down
10 changes: 7 additions & 3 deletions models/Jobs/DBBatchRepository.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@ component singleton accessors="true" {
}

public void function incrementTotalJobs( required string id, required numeric count ) {
qb.table( variables.batchTableName )
var builder = qb.table( variables.batchTableName );
var grammar = builder.getGrammar();
var totalJobsColumn = grammar.wrapValue( "totalJobs" );
var pendingJobsColumn = grammar.wrapValue( "pendingJobs" );
builder
.where( "id", arguments.id )
.update(
values = {
"totalJobs" : qb.raw( "totalJobs + #count#" ),
"pendingJobs" : qb.raw( "pendingJobs + #count#" ),
"totalJobs" : qb.raw( "#totalJobsColumn# + #arguments.count#" ),
"pendingJobs" : qb.raw( "#pendingJobsColumn# + #arguments.count#" ),
"completedDate" : { "value" : 0, "null" : true }
},
options = variables.defaultQueryOptions
Expand Down
10 changes: 10 additions & 0 deletions models/Providers/AbstractQueueProvider.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ component accessors="true" {
numeric currentAttempt
) {
var config = deserializeJSON( arguments.payload );
if (
!config.keyExists( "mapping" ) || isNull( config.mapping ) || !isSimpleValue( config.mapping ) || trim(
config.mapping
) == ""
) {
throw(
type = "cbq.InvalidJobMapping",
message = "Job ###arguments.jobId# has no usable mapping and cannot be executed."
);
}

if ( !variables.wirebox.containsInstance( config.mapping ) ) {
throw(
Expand Down
12 changes: 11 additions & 1 deletion models/Providers/BoxLangQueuePoll.bx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ class {
var settings = getApplicationMetadata();
var applicationName = settings.name;
var pollSettings = {};
for ( var key in [ "mappings", "datasource", "defaultDatasource", "datasources", "javaSettings" ] ) {
for (
var key in [
"mappings",
"datasource",
"defaultDatasource",
"datasources",
"javaSettings",
"ormEnabled",
"ormSettings"
]
) {
if ( settings.keyExists( key ) ) {
pollSettings[ key ] = duplicate( settings[ key ] );
}
Expand Down
12 changes: 12 additions & 0 deletions models/Providers/DBProvider.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,18 @@ component accessors="true" extends="AbstractQueueProvider" {
arguments.record.id,
arguments.record.attempts
);
} catch ( cbq.InvalidJobMapping e ) {
var invalidJob = variables.wirebox.getInstance( "NonExecutableJob@cbq" );
invalidJob.applyMemento( deserializeJSON( arguments.record.payload ) );
invalidJob.setId( arguments.record.id );
invalidJob.setMapping( "[missing mapping]" );
invalidJob.setCurrentAttempt( arguments.record.attempts );
invalidJob.setProviderContext( {
"attempt" : arguments.record.attempts,
"awaitingExecution" : true
} );
markJobFailed( invalidJob, arguments.pool, e );
return;
} catch ( cbq.UnknownJobMapping e ) {
// No execution has started. Release only this fetched reservation so
// another worker can handle it, without consuming an attempt.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/** Preserve complete exception diagnostics in failed-job records. */
component {

function up( schema ) {
schema.alter( "cbq_failed_jobs", function( t ) {
t.modifyColumn( "exceptionType", t.longText( "exceptionType" ).nullable() );
t.modifyColumn( "exceptionMessage", t.longText( "exceptionMessage" ) );
t.modifyColumn( "exceptionDetail", t.longText( "exceptionDetail" ).nullable() );
} );
}

function down( schema ) {
schema.alter( "cbq_failed_jobs", function( t ) {
t.modifyColumn( "exceptionType", t.string( "exceptionType" ).nullable() );
t.modifyColumn( "exceptionMessage", t.string( "exceptionMessage" ) );
t.modifyColumn( "exceptionDetail", t.string( "exceptionDetail" ).nullable() );
} );
}

}
84 changes: 84 additions & 0 deletions tests/specs/integration/OpenIssueRegressionSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,90 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {

function run() {
describe( "reported configuration regressions", function() {
it( "fails a poison database job with no mapping instead of blocking its queue", function() {
var provider = getInstance( "DBProvider@cbq" ).setProperties( {} );
var cbqSettings = getInstance( "coldbox:moduleSettings:cbq" );
var originalLogFailedJobs = cbqSettings.logFailedJobs;
makePublic( provider, "processLockedRecord" );
var pool = getInstance( "WorkerPool@cbq" ).setName( "InvalidMapping" );
var queue = "invalid-mapping-#createUUID()#";
provider.push( queue, getInstance( "@cbq" ).job( "MissingOnThisWorker" ) );
var row = provider
.newQuery()
.from( "cbq_jobs" )
.where( "queue", queue )
.first();
var payload = deserializeJSON( row.payload );
payload.mapping = javacast( "null", "" );
provider
.newQuery()
.from( "cbq_jobs" )
.where( "id", row.id )
.update( {
"payload" : serializeJSON( payload ),
"reservedBy" : pool.getUniqueId()
} );
row.payload = serializeJSON( payload );
try {
cbqSettings.logFailedJobs = true;
provider.processLockedRecord( row, pool );
} finally {
cbqSettings.logFailedJobs = originalLogFailedJobs;
}
var after = provider
.newQuery()
.from( "cbq_jobs" )
.where( "id", row.id )
.first();
expect( after.failedDate ?: "" ).notToBe( "" );
expect( after.attempts ).toBe( 0 );
expect(
getInstance( "QueryBuilder@qb" )
.from( "cbq_failed_jobs" )
.where( "originalId", toString( row.id ) )
.where( "exceptionType", "cbq.InvalidJobMapping" )
.count()
).toBe( 1 );
} );

it( "logs exception diagnostics longer than 255 characters", function() {
var cbqSettings = getInstance( "coldbox:moduleSettings:cbq" );
var originalLogFailedJobs = cbqSettings.logFailedJobs;
var originalId = createUUID();
var longValue = repeatString( "diagnostic-", 40 );
var job = getInstance( "@cbq" )
.job( "MissingOnThisWorker" )
.setId( originalId )
.onConnection( "db" )
.onQueue( "long-diagnostics" );
try {
cbqSettings.logFailedJobs = true;
controller
.getInterceptorService()
.announce(
"onCBQJobFailed",
{
"job" : job,
"exception" : {
"type" : longValue,
"message" : longValue,
"detail" : longValue,
"stackTrace" : longValue
}
}
);
} finally {
cbqSettings.logFailedJobs = originalLogFailedJobs;
}
var failedLog = getInstance( "QueryBuilder@qb" )
.from( "cbq_failed_jobs" )
.where( "originalId", originalId )
.first();
expect( failedLog.exceptionType ).toBe( longValue );
expect( failedLog.exceptionMessage ).toBe( longValue );
expect( failedLog.exceptionDetail ).toBe( longValue );
} );

it( "stores batches with no optional lifecycle jobs", function() {
var batch = getInstance( "@cbq" ).batch( [] );
var options = batch.getOptions();
Expand Down
Loading