• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

violinist-dev / queue-starter / 10588112174

23 Aug 2024 04:44PM UTC coverage: 68.571%. Remained the same
10588112174

push

github

web-flow
Run tests every night (#135)

38 of 80 branches covered (47.5%)

Branch coverage included in aggregate %.

250 of 340 relevant lines covered (73.53%)

26.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.15
/src/createJob.ts
1
/* eslint no-unused-vars: "off" */
2
/* eslint @typescript-eslint/no-unused-vars: "error" */
3
import * as util from 'util'
3✔
4
import * as Docker from 'dockerode'
3✔
5
import { Runlog } from './RunLog'
3✔
6
import Publisher from './publisher'
3✔
7
import { Writable } from 'stream'
3✔
8
import { Job } from './job'
9
import promisify from './promisify'
3✔
10
const docker = new Docker()
3✔
11
const request = require('request')
3✔
12

13
const binds = []
3✔
14
const getHostConfig = function (type: string, config) {
3✔
15
  const hostConfig = {
10✔
16
    Memory: 2147483648,
17
    Binds: binds,
18
    autoRemove: true,
19
    ExtraHosts: []
20
  }
21
  if (type === 'update') {
10!
22
    // For now just making sure the coding standard is correct.
23
    hostConfig.Binds = []
10✔
24
  }
25
  if (config.extraHosts) {
10!
26
    hostConfig.ExtraHosts = config.extraHosts
×
27
  }
28
  return hostConfig
10✔
29
}
30
function createJob (config, job: Job, gitRev) {
31
  return async function (callback) {
10✔
32
    const data = job.data
10✔
33
    data.violinist_revision = gitRev
10✔
34
    data.violinist_hostname = config.hostname
10✔
35
    if (!data.php_version) {
10✔
36
      data.php_version = '8.0'
1✔
37
    }
38
    if (!data.composer_version) {
10!
39
      data.composer_version = '2'
10✔
40
    }
41
    let dockerImage = util.format('ghcr.io/violinist-dev/update-check-runner:%s-multi-composer-%s', data.php_version, data.composer_version)
10✔
42
    // Of course, if the job is trying to say that the type is different, we might want to also use a different image.
43
    let type = 'update'
10✔
44
    if (data.type === 'violinist_needs_update_checker') {
10!
45
      dockerImage = 'needs-update-check-runner'
×
46
      type = 'needsUpdate'
×
47
    }
48
    var runLog = new Runlog(data)
10✔
49
    runLog.log.info('Using image', dockerImage)
10✔
50
    const publisher = new Publisher(config)
10✔
51
    var j = request.jar()
10✔
52
    var cookie = request.cookie('XDEBUG_SESSION=PHPSTORM')
10✔
53
    var baseUrl = config.baseUrl
10✔
54
    j.setCookie(cookie, baseUrl)
10✔
55
    var postData = {
10✔
56
      message: {},
57
      jobId: data.job_id,
58
      set_state: 'processing',
59
      token: config.token
60
    }
61
    var stdout = new Writable()
10✔
62
    var stdoutdata = []
10✔
63
    stdout._write = function (chunk, enc, next) {
10✔
64
      stdoutdata.push(chunk.toString())
1✔
65
      next()
1✔
66
    }
67
    var stderr = new Writable()
10✔
68
    var stderrdata = []
10✔
69
    stderr._write = function (chunk, enc, next) {
10✔
70
      stderrdata.push(chunk.toString())
×
71
      next()
×
72
    }
73
    var env = []
10✔
74
    Object.keys(data).forEach((n) => {
10✔
75
      var val = data[n]
42✔
76
      env.push(`${n}=${val}`)
42✔
77
    })
78
    runLog.log.info('Starting container for', data.slug)
10✔
79
    var startTime = Date.now()
10✔
80
    try {
81
      const container = await docker.run(dockerImage, ['php', 'runner.php'], [stdout, stderr], {
10✔
82
        HostConfig: getHostConfig(type, config),
83
        Env: env,
84
        Binds: binds,
85
        TTy: false
86
      })
87
      const totalTime = Date.now() - startTime
10✔
88
      runLog.log.info({ containerTime: totalTime }, 'Total time was ' + totalTime)
10✔
89
      const code = container.output.StatusCode
10✔
90
      runLog.log.info('Container ended with status code ' + code)
10✔
91
      const message = {
10✔
92
        stderr: stderrdata,
93
        stdout: stdoutdata
94
      }
95
      if (code === 0) {
20!
96
        // Notify about the good news.
97
        postData.set_state = 'success'
×
98
        postData.message = message
×
99
        runLog.log.info('Posting job data')
×
100
        const data = await promisify(publisher.publish.bind(publisher, postData))
×
101
        runLog.log.info('Job complete request code: ' + data.statusCode)
×
102
      } else {
103
        postData.set_state = 'failure'
10✔
104
        runLog.log.warn('Status code was not 0, it was: ' + code)
10✔
105
        runLog.log.warn('Data from container:', {
10✔
106
          message: message
107
        })
108
        postData.message = message
10✔
109
        runLog.log.info('Posting error data to endpoint')
10✔
110
        const data = await promisify(publisher.publish.bind(publisher, postData))
10✔
111
        runLog.log.info('Job complete request code: ' + data.statusCode)
10✔
112
      }
113
      runLog.log.info('container removed')
10✔
114
      callback()
10✔
115
    } catch (err) {
116
      runLog.log.error(err, 'Error with container things')
1✔
117
      callback()
1✔
118
    }
119
  }
120
}
121

122
module.exports = createJob
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc