             importer = new OrderStatus resources.options
             processSftpImport(resources, importer, 'orderStatus')
           .then ->
-            @exitCode = 0
-          .fail (error) ->
-            logger.error error, 'Oops, something went wrong!'
-            logger.error error.stack if error.stack
-            @exitCode = 1
+            @_setExitCode 0
+          .fail (error) ->
+            logger.error error, 'Oops, something went wrong!'
+            logger.error error.stack if error.stack
+            @_setExitCode 1
         else # use command line arguments to load import/export files
           validateCredentialsOpts(opts, CONS.CMD_IMPORT_ORDERS_STATUS)
           validateOpt(opts.status, 'status', CONS.CMD_IMPORT_ORDERS_STATUS)


module.exports = class

  # workaround to make sure that all logger streams are flushed properly before node terminates
  process.on 'exit', => process.exit(@exitCode)

  @run: (argv) ->
    program

            importer = new ProductUpdates options
            importFn(importer, opts.products, mapping, logger)
          .then ->
            @_setExitCode 0
          .fail (error) ->
            logger.error error, 'Oops, something went wrong!'
            logger.error error.stack if error.stack
            @_setExitCode 1

    program
      .command CONS.CMD_EXPORT_ORDERS
