Skip to content

Commit a8203eb

Browse files
committed
convert datatime format for graphql fix #210
1 parent 61aed4c commit a8203eb

File tree

7 files changed

+142
-125
lines changed

7 files changed

+142
-125
lines changed

sdk/cli-py/proca/cmd/action.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def requeue(ctx, org, campaign, include_testing, start_id, start_datetime, queue
8888
requeue_mut = gql(requeue_str)
8989

9090
def get_ids(next_id=None):
91-
results = ctx.client.execute(query_ids, **vars(org=org, campaign=campaign, includeTesting=include_testing, startId=next_id, startDatetime=start_datetime))
91+
string_start_datetime = start_datetime.strftime("%Y-%m-%dT%H:%M:%SZ")
92+
results = ctx.client.execute(query_ids, **vars(org=org, campaign=campaign, includeTesting=include_testing, startId=next_id, startDatetime=string_start_datetime))
9293

9394
# Yield each ID from the results
9495
results = results['exportActions']

sdk/cli-py/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setuptools.setup(
1212
name="proca",
13-
version="0.3.5",
13+
version="0.3.7",
1414
author="Marcin Koziej",
1515
author_email="[email protected]",
1616
description="Proca CLI to use with Proca service",

sdk/queue/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
],
4646
"devDependencies": {
4747
"@size-limit/preset-small-lib": "^7.0.8",
48-
"@types/amqplib": "^0.8.2",
4948
"@types/line-by-line": "^0.1.6",
5049
"husky": "^7.0.4",
5150
"size-limit": "^7.0.8",
@@ -55,8 +54,8 @@
5554
},
5655
"dependencies": {
5756
"@proca/crypto": "^3.4.0",
58-
"amqplib": "^0.8.0",
59-
"line-by-line": "^0.1.6"
57+
"line-by-line": "^0.1.6",
58+
"rabbitmq-client": "^3.3.2"
6059
},
6160
"gitHead": "635a7c1b39cd036c8d9fe111b3c9fd0c325eada6"
6261
}

sdk/queue/src/queue.ts

+76-19
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import { decryptPersonalInfo } from '@proca/crypto'
2-
import amqplib from 'amqplib'
2+
import Connection from 'rabbitmq-client'
33
import LineByLine from 'line-by-line'
44
export {ActionMessage, ActionMessageV2, ProcessStage} from './actionMessage'
55

6-
import {
7-
ActionMessage,
8-
actionMessageV1to2
9-
} from './actionMessage'
10-
116
import {QueueOpts, SyncCallback} from './types'
127

138

@@ -20,19 +15,83 @@ const pause = (time = 1) => { //by default, wait 1 sec
2015
}
2116

2217
export async function testQueue(queueUrl : string, queueName : string) {
23-
const conn = await connect(queueUrl)
24-
const ch = await conn.createChannel()
25-
try {
26-
const status = await ch.checkQueue(queueName)
27-
return status
28-
} finally {
29-
ch.close()
30-
conn.close()
31-
}
18+
const rabbit = new Connection({
19+
url: queueUrl,
20+
// wait 1 to 30 seconds between connection retries
21+
retryLow: 1000,
22+
retryHigh: 30000,
23+
})
24+
const ch = await rabbit.acquire()
25+
const status = ch.queueDeclare({queue: queueName,passive:true});
26+
console.log(status);
27+
await ch.close();
28+
await rabbit.close();
29+
30+
process.exit(1)
3231
}
3332

3433

35-
export async function syncQueue(
34+
const export async syncQueue = (
35+
queueUrl : string,
36+
queueName : string,
37+
syncer : SyncCallback,
38+
opts? : QueueOpts
39+
)=> {
40+
let errorCount = 0; //number of continuous errors
41+
42+
const rabbit = new Connection({
43+
url: queueUrl,
44+
// wait 1 to 30 seconds between connection retries
45+
retryLow: 1000,
46+
retryHigh: 30000,
47+
})
48+
49+
rabbit.on('error', (err) => {
50+
// connection refused, etc
51+
console.error(err)
52+
})
53+
54+
rabbit.on('connection', () => {
55+
console.log('The connection is successfully (re)established')
56+
})
57+
58+
const consumer = rabbit.createConsumer({
59+
queue: queueName,
60+
queueOptions: {exclusive: true}, //one consumer only?
61+
// handle 2 messages at a time,
62+
concurrency: 1 ,
63+
qos: {prefetchCount: 2},
64+
}, async (msg) => {
65+
console.log(msg)
66+
let action : ActionMessage = JSON.parse(msg.content.toString())
67+
68+
// upgrade old v1 message format to v2
69+
if (action.schema === "proca:action:1") {
70+
action = actionMessageV1to2(action)
71+
}
72+
73+
// optional decrypt
74+
if (action.personalInfo && opts?.keyStore) {
75+
const plainPII = decryptPersonalInfo(action.personalInfo, opts.keyStore)
76+
action.contact = {...action.contact, ...plainPII}
77+
}
78+
79+
const processed = await syncer(action, msg, ch);
80+
if (!processed) {
81+
throw new Error ("aaa");
82+
}
83+
throw new Error ("bb");
84+
85+
// msg is automatically acknowledged when this function resolves or msg is
86+
// rejected (and maybe requeued, or sent to a dead-letter-exchange) if this
87+
// function throws an error
88+
})
89+
90+
91+
}
92+
93+
/*
94+
export async function NOKsyncQueue(
3695
queueUrl : string,
3796
queueName : string,
3897
syncer : SyncCallback,
@@ -68,7 +127,6 @@ export async function syncQueue(
68127
}
69128
console.error(`⏳ waiting for actions from ${qn}`)
70129
71-
return new Promise(async (_, _fail) => {
72130
if (typeof opts?.prefetch !== 'undefined') {
73131
await ch.prefetch(opts.prefetch)
74132
}
@@ -132,9 +190,8 @@ export async function syncQueue(
132190
}
133191
})
134192
status.tag = ret.consumerTag
135-
})
136193
}
137-
194+
*/
138195
export async function syncFile(filePath : string, syncer : SyncCallback, opts? : QueueOpts) {
139196
const lines = new LineByLine(filePath)
140197

0 commit comments

Comments
 (0)