简体   繁体   中英

Multiple targets in Vapor Xcode project

I'm working with Vapor in Xcode, deploying to Heroku. My web app is working perfectly. Really pleased with Vapor and how easy it is to deploy to Heroku.

I'm now trying to create a separate Heroku Worker process in the same project. I've added the new worker to my Heroku Procfile, but I am not clear how I should set up the second target in the Xcode project so that it doesn't get overwritten every time I run vapor xcode to rebuild the project file.

My Procfile looks like this:

web: App --env=production --workdir=./ --config:servers.default.port=$PORT --config:postgresql.url=$DATABASE_URL
worker: Worker --env=production --workdir=./ --config:servers.default.port=$PORT --config:postgresql.url=$DATABASE_URL

So, as you can see, I simply want a second app executable called Worker that I can start up within a Heroku worker dyno.

Any idea how I can have a web App target and a separate worker target in my Xcode project that won't get overwritten by vapor xcode ?

Thanks --TJ

Ah hah! Solved it. In order to have multiple targets in the project, you need to define them in the Package.swift file for the Swift package manager that is responsible for building the project file.

So, my Package.swift now looks like this:

import PackageDescription

let package = Package(
    name: "myapp",
    targets: [
        Target(name: "App", dependencies: ["Shared"]),
        Target(name: "Worker", dependencies: ["Shared"]),
    ],
    dependencies: [
    ],
    exclude: [
        "Config",
        "Database",
        "Localization",
        "Public",
        "Resources",
        ]
)

My Sources directory structure now looks like this:

Sources | - App - Worker - Shared

The Shared target contains all of my shared code that is required by the App and the Worker executable targets.

Now, defining the Procfile as above works perfectly. I now have a web app, and a worker process.

Cheers --TJ

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM