dagster-dingtalk 0.1.5b2__py3-none-any.whl → 0.1.6__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -176,13 +176,14 @@ class DingTalkResource(ConfigurableResource):
176
176
  def _get_access_token(self) -> str:
177
177
  access_token_cache = Path("/tmp/.dingtalk_cache")
178
178
 
179
- if access_token_cache.exists():
179
+ try:
180
180
  with open(access_token_cache, 'rb') as f:
181
181
  all_access_token: Dict[str, Tuple[str, int]] = pickle.loads(f.read())
182
- else:
182
+ access_token, expire_in = all_access_token.get(self.AppID, ('', 0))
183
+ except Exception as e:
184
+ print(e)
183
185
  all_access_token = {}
184
-
185
- access_token, expire_in = all_access_token.get(self.AppID, ('', 0))
186
+ access_token, expire_in = all_access_token.get(self.AppID, ('', 0))
186
187
 
187
188
  if access_token and expire_in < int(time.time()):
188
189
  return access_token
@@ -196,29 +197,35 @@ class DingTalkResource(ConfigurableResource):
196
197
  expire_in:int = response.json().get("expireIn") + int(time.time()) - 60
197
198
  with open(access_token_cache, 'wb') as f:
198
199
  all_access_token[self.AppID] = (access_token, expire_in)
199
- f.write(pickle.dumps(access_token_cache))
200
+ f.write(pickle.dumps(all_access_token))
200
201
  return access_token
201
202
 
203
+ def _init_client(self):
204
+ if not hasattr(self, '_client'):
205
+ self._client = DingTalkClient(
206
+ self._get_access_token(),
207
+ self.AppID,
208
+ self.AgentID,
209
+ self.RobotCode or self.ClientId
210
+ )
211
+
202
212
  def setup_for_execution(self, context: InitResourceContext) -> None:
203
- self._client = DingTalkClient(self._get_access_token(), self.AppID, self.AgentID, self.RobotCode or self.ClientId)
213
+ self._init_client()
204
214
 
205
215
  def teardown_after_execution(self, context: InitResourceContext) -> None:
206
216
  self._client.api.close()
207
217
  self._client.oapi.close()
208
218
 
209
219
  def 智能人事(self):
210
- if not hasattr(self, '_client'):
211
- self._client = DingTalkClient(self._get_access_token(), self.AppID, self.AgentID, self.RobotCode or self.ClientId)
220
+ self._init_client()
212
221
  return API_智能人事(self._client)
213
222
 
214
223
  def 通讯录管理(self):
215
- if not hasattr(self, '_client'):
216
- self._client = DingTalkClient(self._get_access_token(), self.AppID, self.AgentID, self.RobotCode or self.ClientId)
224
+ self._init_client()
217
225
  return API_通讯录管理(self._client)
218
226
 
219
227
  def 文档文件(self):
220
- if not hasattr(self, '_client'):
221
- self._client = DingTalkClient(self._get_access_token(), self.AppID, self.AgentID, self.RobotCode or self.ClientId)
228
+ self._init_client()
222
229
  return API_文档文件(self._client)
223
230
 
224
231
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dagster-dingtalk
3
- Version: 0.1.5b2
3
+ Version: 0.1.6
4
4
  Summary: A dagster plugin for the DingTalk
5
5
  Author: YiZixuan
6
6
  Author-email: sqkkyzx@qq.com
@@ -0,0 +1,7 @@
1
+ dagster_dingtalk/__init__.py,sha256=ktvoURpkJwIzcyQfUvnel1KA4DukRgavAgLl7f0Cy_0,440
2
+ dagster_dingtalk/operations.py,sha256=xJJlOVmFjpaDTMkHZXxj5LbXqRtIQwREl9ZJdXIMOyE,788
3
+ dagster_dingtalk/resources.py,sha256=P5PW7xpIZ5FXyWsgIODR7RNRzysYeq7q0yrofIA3RdQ,15015
4
+ dagster_dingtalk/version.py,sha256=sXLh7g3KC4QCFxcZGBTpG2scR7hmmBsMjq6LqRptkRg,22
5
+ dagster_dingtalk-0.1.6.dist-info/METADATA,sha256=oQkzvE9EHHrNTT8kMLn2EiQw0Gh0uQKhVxjXAyIAR2Y,1659
6
+ dagster_dingtalk-0.1.6.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
+ dagster_dingtalk-0.1.6.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- dagster_dingtalk/__init__.py,sha256=ktvoURpkJwIzcyQfUvnel1KA4DukRgavAgLl7f0Cy_0,440
2
- dagster_dingtalk/operations.py,sha256=xJJlOVmFjpaDTMkHZXxj5LbXqRtIQwREl9ZJdXIMOyE,788
3
- dagster_dingtalk/resources.py,sha256=zZkrrSff8lW59D6FEw1_01GyhcMAgL6TN3hOD21p9AE,15159
4
- dagster_dingtalk/version.py,sha256=sXLh7g3KC4QCFxcZGBTpG2scR7hmmBsMjq6LqRptkRg,22
5
- dagster_dingtalk-0.1.5b2.dist-info/METADATA,sha256=xeX9IPCeb_vufDg7NvaATUO5PKfLFeFgx_lb_7NdVh4,1661
6
- dagster_dingtalk-0.1.5b2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
- dagster_dingtalk-0.1.5b2.dist-info/RECORD,,