Skip to content

Commit

Permalink
Merge branch 'main' into rc-jobs-clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Walker-GM authored Sep 18, 2024
2 parents b1e58fc + 705ea5b commit dd87972
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .changesets/11572.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Default NODE_ENV to "development" if it's `undefined` when starting jobs worker (#11572) by @cannikin

This mimics the behavior of `yarn rw dev` where `NODE_ENV` will equal `development` if you don't set it explicitly.
2 changes: 1 addition & 1 deletion __fixtures__/test-project/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"postcss": "^8.4.47",
"postcss-loader": "^8.1.1",
"prettier-plugin-tailwindcss": "^0.5.12",
"tailwindcss": "^3.4.11"
"tailwindcss": "^3.4.12"
}
}
16 changes: 15 additions & 1 deletion docs/docs/background-jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ By checking the `lastError` field in the database you can see what the last erro
## Deployment
For many use cases you may simply be able to rely on the job runner to start your job workers, which will run forever:
For many use cases you may be able to rely on the job runner to start and detach your job workers, which will then run forever:
```bash
yarn rw jobs start
Expand All @@ -723,6 +723,20 @@ Of course if you have a process monitor system watching your workers you'll want
:::
### NODE_ENV
You'll need to explicitly set your `NODE_ENV` when in environments other than development or test. We like having a `.env` file in a serverfull production environment, and you just include:
```bash
NODE_ENV=production
```
If you're using Docker, make sure you have an `ENV` declaration for it:
```docker
ENV NODE_ENV="production"
```
## Advanced Job Workers
As noted above, although the workers are started and detached using the `yarn rw jobs start` command, there is nothing to monitor those workers to make sure they keep running. To do that, you'll want to start the workers yourself (or have your process monitor start them) using command line flags.
Expand Down
16 changes: 15 additions & 1 deletion docs/versioned_docs/version-8.0/background-jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ By checking the `lastError` field in the database you can see what the last erro
## Deployment
For many use cases you may simply be able to rely on the job runner to start your job workers, which will run forever:
For many use cases you may be able to rely on the job runner to start and detach your job workers, which will then run forever:
```bash
yarn rw jobs start
Expand All @@ -727,6 +727,20 @@ Of course if you have a process monitor system watching your workers you'll want
:::
### NODE_ENV
You'll need to explicitly set your `NODE_ENV` when in environments other than development or test. We like having a `.env` file in a serverfull production environment, and you just include:
```bash
NODE_ENV=production
```
If you're using Docker, make sure you have an `ENV` declaration for it:
```docker
ENV NODE_ENV="production"
```
## Advanced Job Workers
As noted above, although the workers are started and detached using the `yarn rw jobs start` command, there is nothing to monitor those workers to make sure they keep running. To do that, you'll want to start the workers yourself (or have your process monitor start them) using command line flags.
Expand Down
16 changes: 15 additions & 1 deletion docs/versioned_docs/version-8.1/background-jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ By checking the `lastError` field in the database you can see what the last erro
## Deployment
For many use cases you may simply be able to rely on the job runner to start your job workers, which will run forever:
For many use cases you may be able to rely on the job runner to start and detach your job workers, which will then run forever:
```bash
yarn rw jobs start
Expand All @@ -723,6 +723,20 @@ Of course if you have a process monitor system watching your workers you'll want
:::
### NODE_ENV
You'll need to explicitly set your `NODE_ENV` when in environments other than development or test. We like having a `.env` file in a serverfull production environment, and you just include:
```bash
NODE_ENV=production
```
If you're using Docker, make sure you have an `ENV` declaration for it:
```docker
ENV NODE_ENV=production
```
## Advanced Job Workers
As noted above, although the workers are started and detached using the `yarn rw jobs start` command, there is nothing to monitor those workers to make sure they keep running. To do that, you'll want to start the workers yourself (or have your process monitor start them) using command line flags.
Expand Down
29 changes: 29 additions & 0 deletions packages/jobs/src/__tests__/setupEnv.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, expect, it, vi, afterEach } from 'vitest'

import { setupEnv } from '../setupEnv'

vi.mock('@redwoodjs/cli-helpers/loadEnvFiles', () => {
return {
loadEnvFiles: () => {},
}
})

const ORIGNAL_NODE_ENV = process.env.NODE_ENV

describe('setupEnv', () => {
afterEach(() => {
process.env.NODE_ENV = ORIGNAL_NODE_ENV
})

it('if not called, NODE_ENV is not overridden in any way', () => {
expect(process.env.NODE_ENV).toEqual(ORIGNAL_NODE_ENV)
})

it('sets NODE_ENV to development if it starts undefined', () => {
delete process.env.NODE_ENV

setupEnv()

expect(process.env.NODE_ENV).toEqual('development')
})
})
5 changes: 2 additions & 3 deletions packages/jobs/src/bins/rw-jobs-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import process from 'node:process'
import { hideBin } from 'yargs/helpers'
import yargs from 'yargs/yargs'

import { loadEnvFiles } from '@redwoodjs/cli-helpers/loadEnvFiles'

import { PROCESS_TITLE_PREFIX } from '../consts.js'
import type { Worker } from '../core/Worker.js'
import { WorkerConfigIndexNotFoundError } from '../errors.js'
import { loadJobsManager } from '../loaders.js'
import { setupEnv } from '../setupEnv.js'

loadEnvFiles()
setupEnv()

const parseArgs = (argv: string[]) => {
return yargs(hideBin(argv))
Expand Down
5 changes: 2 additions & 3 deletions packages/jobs/src/bins/rw-jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import { setTimeout } from 'node:timers'
import { hideBin } from 'yargs/helpers'
import yargs from 'yargs/yargs'

import { loadEnvFiles } from '@redwoodjs/cli-helpers/loadEnvFiles'

import { DEFAULT_LOGGER, PROCESS_TITLE_PREFIX } from '../consts.js'
import { loadJobsManager } from '../loaders.js'
import { setupEnv } from '../setupEnv.js'
import type {
Adapters,
BasicLogger,
Expand All @@ -26,7 +25,7 @@ import type {

export type NumWorkersConfig = [number, number][]

loadEnvFiles()
setupEnv()

process.title = 'rw-jobs'

Expand Down
11 changes: 11 additions & 0 deletions packages/jobs/src/setupEnv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { loadEnvFiles } from '@redwoodjs/cli-helpers/loadEnvFiles'

export const setupEnv = () => {
loadEnvFiles()

// If even after loading `.env` we find that `NODE_ENV` is `undefined` default
// to `development` to mimic what the other CLI tools to
if (process.env.NODE_ENV === undefined) {
process.env.NODE_ENV = 'development'
}
}
2 changes: 1 addition & 1 deletion packages/ogimage-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"ts-toolbelt": "9.6.0",
"tsx": "4.19.1",
"typescript": "5.6.2",
"vite": "5.4.5",
"vite": "5.4.6",
"vitest": "2.0.5"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"@types/node": "20.16.5",
"tsx": "4.19.1",
"typescript": "5.6.2",
"vite": "5.4.5"
"vite": "5.4.6"
},
"peerDependencies": {
"@redwoodjs/project-config": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"react": "19.0.0-rc-f2df5694-20240916",
"react-server-dom-webpack": "19.0.0-rc-f2df5694-20240916",
"rimraf": "6.0.1",
"vite": "5.4.5",
"vite": "5.4.6",
"vite-plugin-cjs-interop": "2.1.3",
"vite-plugin-node-polyfills": "0.22.0",
"ws": "8.18.0",
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8469,7 +8469,7 @@ __metadata:
ts-toolbelt: "npm:9.6.0"
tsx: "npm:4.19.1"
typescript: "npm:5.6.2"
vite: "npm:5.4.5"
vite: "npm:5.4.6"
vitest: "npm:2.0.5"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -8795,7 +8795,7 @@ __metadata:
rollup: "npm:4.21.2"
tsx: "npm:4.19.1"
typescript: "npm:5.6.2"
vite: "npm:5.4.5"
vite: "npm:5.4.6"
vite-plugin-cjs-interop: "npm:2.1.3"
vite-plugin-node-polyfills: "npm:0.22.0"
vitest: "npm:2.0.5"
Expand Down Expand Up @@ -27627,7 +27627,7 @@ __metadata:
tsx: "npm:4.19.1"
typescript: "npm:5.6.2"
unplugin-auto-import: "npm:0.18.3"
vite: "npm:5.4.5"
vite: "npm:5.4.6"
peerDependencies:
"@redwoodjs/project-config": "workspace:*"
"@redwoodjs/router": "workspace:*"
Expand Down Expand Up @@ -29670,9 +29670,9 @@ __metadata:
languageName: node
linkType: hard

"vite@npm:5.4.5, vite@npm:^5.0.0":
version: 5.4.5
resolution: "vite@npm:5.4.5"
"vite@npm:5.4.6, vite@npm:^5.0.0":
version: 5.4.6
resolution: "vite@npm:5.4.6"
dependencies:
esbuild: "npm:^0.21.3"
fsevents: "npm:~2.3.3"
Expand Down Expand Up @@ -29709,7 +29709,7 @@ __metadata:
optional: true
bin:
vite: bin/vite.js
checksum: 10c0/89c6459452fc238cdf8e99681b30996af171c9c557af476f96408a18a639fb5a0a6ee2d2257e005b21dc284edceb604595c34920cd4a007ad18f7ebafb654c76
checksum: 10c0/5f87be3a10e970eaf9ac52dfab39cf9fff583036685252fb64570b6d7bfa749f6d221fb78058f5ef4b5664c180d45a8e7a7ff68d7f3770e69e24c7c68b958bde
languageName: node
linkType: hard

Expand Down

0 comments on commit dd87972

Please sign in to comment.